goravel / goravel Goto Github PK
View Code? Open in Web Editor NEWA Golang framework for web artisans. Tribute to Laravel.
Home Page: https://goravel.dev
License: MIT License
A Golang framework for web artisans. Tribute to Laravel.
Home Page: https://goravel.dev
License: MIT License
having this model
type Player struct {
orm.Model
User *User
UserID string
ClubId string
Club *Club
FirstName string
LastName string
PlayerTypeID string
PlayerType *PlayerType
Street string
City string
PostalCode string
Country string
ContactName string
ContactPhone string
}
with at least 3 models associated
At the moment of create the User also create the player
so I can get the values of User querying player
facades.Orm.Query().Select(orm.Associations).Create(&player)
facades.Orm.Query().Model(&player).Association("User").Find(&player)
ctx.Response().Json(http.StatusOK, contractshttp.Json{
"message": "User saved",
"data": &player,
"action": action,
})
http -f POST localhost:3000/users name="user3" password="1234" player_type_id=1 first_name="pepe" last_name="dsads" club_id=8 country="mexico" street="dasdasda" postal_code="dasda" contact_phone="sdas" contact_name="dasdas" email="[email protected]"
HTTP/1.1 200 OK
Content-Length: 844
Content-Type: application/json; charset=utf-8
Date: Tue, 07 Mar 2023 01:12:35 GMT
Vary: Origin
{
"action": "create",
"data": {
"City": "",
"Club": {
"City": "",
"ContactEmail": "",
"ContactName": "",
"ContactPhone": "",
"Country": "",
"CreatedAt": "0001-01-01T00:00:00Z",
"Description": "",
"ID": 8,
"Name": "",
"Organization": null,
"OrganizationId": "",
"PostalCode": "",
"Street": "",
"UpdatedAt": "0001-01-01T00:00:00Z"
},
"ClubId": "8",
"ContactName": "dasdas",
"ContactPhone": "sdas",
"Country": "mexico",
"CreatedAt": "0001-01-01T00:00:00Z",
"FirstName": "pepe",
"ID": 0,
"LastName": "dsads",
"PlayerType": null,
"PlayerTypeID": "1",
"PostalCode": "dasda",
"Street": "dasdasda",
"UpdatedAt": "0001-01-01T00:00:00Z",
"User": {
"Avatar": "",
"CreatedAt": "2023-03-07T01:12:35.702Z",
"DeletedAt": null,
"Email": "[email protected]",
"ID": 57,
"Name": "user3",
"Password": "$2a$10$VtamLUPqCvHlfBlwEOpzKOGhqyuE9vcjPjRc6y8QuCLoGNgkLoSTG",
"UpdatedAt": "2023-03-07T01:12:35.702Z"
},
"UserID": "57"
},
"message": "User saved"
}
everything looks good to here
however, when I want to also associate model club or player_type only returns associated values, I would need to query those models separatedly so the associated models can populate player model and return belonging results,
I tried instantiating those models and assign ID value, and yet brings empty object from model, my expectation here is the ORM query joins given the association and ID, and only works querying each model separatedly, is my expectation realistic (I used to do it like this in laravel) or I am missing something?
Can you please suggest how can I implement different auth approaches: session
, api-key
, jwt
?
I see that currently it has just jwt authentication
可以参照框架 https://github.com/qit-team/snow
也是按照laravel的架构设计进行设计的go框架。
有很好的的生产实践经验,在公司线上环境有大量的应用,支撑这公司大量的业务场景。经过多年的优化,目前的版本比较稳定。
facades.Config.Set(map[string]any{
"app.name": "local"
})
Hi, thanks for this great project, I'm a laravel developer, I'm wondering is there any tuto how to work with views same as Laravel.
Reference: https://laravel.com/docs/9.x/notifications
想使用gorm原生的Clauses
Goravel doesn't support the logic like below, should optimize it.
db := facades.Orm.Query()
db = db.Where()
go: github.com/goravel/[email protected]: reading github.com/goravel/framework/go.mod at revision v0.2.2: unknown revision v0.2.2
Reference: https://laravel.com/docs/9.x/notifications
....\pkg\mod\github.com\golang-migrate\migrate\[email protected]\source\file\file.go:17:2: undefined: iofs.PartialDriver
note: module requires Go 1.16
需要Go 1.16
考虑增加一个自带的限流中间件,用于对接口流量进行速率限制。
Reference: https://laravel.com/docs/9.x/localization
Great work on the package. I'm trying to extend and implement some features and wanted to load some of the service providers only after the configs are full loaded.
Can you please suggest some ways to achieve it?
Forked repo: https://github.com/sujit-baniya/goravel
Reference: https://github.com/briannesbitt/Carbon
The most important function: Time backtracking.
Reference: https://laravel.com/docs/9.x/localization
We need to design the implementation form first.
Enable refresh, reset and rollback options on migrate command
目前市面上大部分存储桶均兼容s3标准,这意味着可以只使用aws s3 sdk就能完成几乎所有存储桶的兼容工作。因此,可以优化移除aliyun oss sdk和tencentcloud cos sdk,缩小打包大小。
hash一般用于密码哈希,Laravel有bcrypt和argon2id
golang.org/x/crypto/bcrypt
golang.org/x/crypto/argon2
crypt用于加密存储,Laravel有 AES-256 和 AES-128
crypto/aes
如果是并发场景下,注册事件时,这个listener能否支持匿名函数呢,并发场景下需要返回一个新的listener对象,比方说这样
func (receiver *EventServiceProvider) listen() map[events.Event][]events.Listener {
return map[events.Event][]events.Listener{
&events.TestEvent{}: {
func() events.Listener {
return &listeners.TestListener{}
},
},
}
}
I checked and found this in gorm.go:
func (r *GormQuery) Find(dest interface{}, conds ...interface{}) error {
return r.instance.Find(dest, conds...).Error
}
func (r *GormQuery) First(dest interface{}) error {
err := r.instance.First(dest).Error
if errors.Is(err, gorm.ErrRecordNotFound) {
return nil
}
return err
}
Why is nil being returned in case of ErrRecordNotFound?
Just like: https://laravel.com/docs/10.x/packages
go get github.com/goravel/sms
go run . artisan vendor:publish --provider="sms"
We need to design the implementation form first.
Need guideance on this.
Working on a Create method with validation, but is not taken, most likely I am doing wrong, working on values validation but is not taken, I must to say I am noob user for golang, this is my method
func (r *OrganizationController) Create(ctx contractshttp.Context) {
organization := models.Organization{
Name: ctx.Request().Form("name",""),
Description: ctx.Request().Form("description", ""),
Street: ctx.Request().Form("street", ""),
City: ctx.Request().Form("city", ""),
PostalCode: ctx.Request().Form("postal_code", ""),
ContactName: ctx.Request().Form("contact_name", ""),
ContactEmail: ctx.Request().Form("contact_email", ""),
ContactPhone: ctx.Request().Form("contact_phone", ""),
Country: ctx.Request().Form("country", ""),
}
validator, err := ctx.Request().Validate(map[string]string{
"name": "required",
"description": "required",
"street": "required",
"city": "required",
"postal_code": "required",
"contact_name": "required",
"contact_email": "required",
"contact_phone": "required",
"country": "required",
});
erro := validator.Bind(&organization)
if erro != nil {
ctx.Response().Json(http.StatusInternalServerError, contractshttp.Json{
"error": err.Error(),
})
return
}
if err := facades.Orm.Query().Create(&organization);
err != nil {
ctx.Response().Json(http.StatusInternalServerError, contractshttp.Json{
"error": err.Error(),
})
return
}
// Fetch orgs
var organizations []models.Organization
if err := facades.Orm.Query().Find(&organizations); err != nil {
ctx.Response().Json(http.StatusInternalServerError, contractshttp.Json{
"error": err.Error(),
})
return
}
ctx.Response().Success().Json(contractshttp.Json{
"organizations": organizations,
"message": ctx.Request().Form("name",""),
})
}
And this is my POST request , removing intentionally some of the fields to cause validation error, but the record is still created
http -f POST localhost:3000/organizations description="wawa" street="sadsaa" country="mexico" city="adsasdas" postal_code="12345" contact_name="pepe" contact_email="emaila"
HTTP/1.1 200 OK
Content-Type: application/json; charset=utf-8
Date: Mon, 20 Feb 2023 23:59:03 GMT
Transfer-Encoding: chunked
Vary: Origin
{
"message": "",
"organizations": [
{
"City": "adsasdas",
"ContactEmail": "emaila",
"ContactName": "pepe",
"ContactPhone": "",
"Country": "mexico",
"CreatedAt": "2023-02-20T23:59:03.088Z",
"Description": "wawa",
"ID": 27,
"Name": "",
"PostalCode": "12345",
"Street": "sadsaa",
"UpdatedAt": "2023-02-20T23:59:03.088Z"
}
]
}
how to fix this and also if could be possible to publish working example for the features as Validation,
Thank you.
Reference: https://github.com/briannesbitt/Carbon
The most important function: Time backtracking.
1.创建了一个新的Command
package commands
import (
"github.com/goravel/framework/contracts/console"
"github.com/goravel/framework/contracts/console/command"
)
type SyncData struct {
}
//Signature The name and signature of the console command.
func (receiver *SyncData) Signature() string {
return "sync:data"
}
//Description The console command description.
func (receiver *SyncData) Description() string {
return "Command description"
}
//Extend The console command extend.
func (receiver *SyncData) Extend() command.Extend {
return command.Extend{}
}
//Handle Execute the console command.
func (receiver *SyncData) Handle(ctx console.Context) error {
return nil
}
2.在控制台执行
go run . artisan sync:data
3.控制台提示
No help topic for 'sync:data'
exit status 3
我写了一个测试脚本,但是因为测试脚本找不到配置文件,panic掉了
Migration failed: Dirty database version 20230309085743. Fix and force version.
For Detail: golang-migrate/migrate#798
goravel/framework v1.3.1
(base) ➜ gorav go run . artisan key:generate
# gorm.io/driver/sqlserver
../../../pkg/mod/gorm.io/driver/[email protected]/sqlserver.go:90:22: cannot convert 0 (untyped int constant) to *int
../../../pkg/mod/gorm.io/driver/[email protected]/sqlserver.go:95:39: cannot use limit.Limit (variable of type *int) as type int in argument to strconv.Itoa
.env 文件没有生成APP_KEY
Enable usage of model Accessors and Mutators to modify model attributes before to be stored to DB or returning query results
Add a configuration to specify table prefix.
type Article struct {
Id uint32 `json:"id"`
Title string `json:"title"`
Content string `json:"content"`
}
func (Article) TableName() string {
return "it_article"
}
db, err := gorm.Open(mysql.Open(dsn), &gorm.Config{
NamingStrategy: schema.NamingStrategy{
TablePrefix: "it_", // 表名前缀,`Article` 的表名应该是 `it_articles`
SingularTable: true, // 使用单数表名,启用该选项,此时,`Article` 的表名应该是 `it_article`
},
})
为了用缓存驱动限流器,需要给缓存增加一个Replace方法用于在不改变原来的到期时间和key的前提下修改缓存值。
缓存将怎么设计?会覆盖哪些场景?
怎么获取一个redis实例呢
I'm trying to create migration using go run . artisan make:migration
for postgresql, but the SQL it generates does't support postgresql. I changed the driver to postgresql but still the same.
Query generated:
CREATE TABLE users (
id bigint(20) unsigned NOT NULL AUTO_INCREMENT,
created_at datetime(3) DEFAULT NULL,
updated_at datetime(3) DEFAULT NULL,
PRIMARY KEY (id),
KEY idx_users_created_at (created_at),
KEY idx_users_updated_at (updated_at)
) ENGINE = InnoDB DEFAULT CHARSET = ;
``
Old
APP_HOST=127.0.0.1:3000
New
APP_HOST=127.0.0.1
APP_PORT=3000
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.