Coder Social home page Coder Social logo

goravel's Introduction

Logo

Doc Go Release Test Report Card Codecov License

English | 中文

About Goravel

Goravel is a web application framework with complete functions and good scalability. As a starting scaffolding to help Gopher quickly build their own applications.

The framework style is consistent with Laravel, let Php developer don't need to learn a new framework, but also happy to play around Golang! In tribute to Laravel!

Welcome to star, PR and issues!

Getting started

// Generate APP_KEY
go run . artisan key:generate

// Route
facades.Route().Get("/", userController.Show)

// ORM
facades.Orm().Query().With("Author").First(&user)

// Task Scheduling
facades.Schedule().Command("send:emails name").EveryMinute()

// Log
facades.Log().Debug(message)

// Cache
value := facades.Cache().Get("goravel", "default")

// Queues
err := facades.Queue().Job(&jobs.Test{}, []queue.Arg{}).Dispatch()

Documentation

Online documentation https://www.goravel.dev

Example https://github.com/goravel/example

To optimize the documentation, please submit a PR to the documentation repository https://github.com/goravel/docs

Main Function

Config Http Authentication Authorization
Orm Migrate Logger Cache
Grpc Artisan Console Task Scheduling Queue
Event FileStorage Mail Validation
Mock Hash Crypt Carbon
Package Development Testing

Roadmap

For Detail

Excellent Extend Packages

For Detail

Contributors

This project exists thanks to all the people who contribute, to participate in the contribution, please see Contribution Guide.

Sponsor

Better development of the project is inseparable from your support, reward us by Open Collective.

Group

Welcome more discussion in Telegram.

https://t.me/goravel

License

The Goravel framework is open-sourced software licensed under the MIT license.

goravel's People

Contributors

devhaozi avatar hwbrzzl avatar iamahens avatar kkumar-gcc avatar sidshrivastav avatar uax avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

goravel's Issues

🐛 [Bug] go run . artisan key:generate无效

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

🐛 [Bug] Creating migration for postgresql doesn't work

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 = ;
``

🐛 [Bug] facades.Orm.Query.First() doesn't return ErrRecordNotFound

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?

🐛 [Bug] 执行Command提示 No help topic for 'sync:data' exit status 3

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

🐛 [Bug] 安装失败

github.com/golang-migrate/migrate/v4/source/file

....\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

laravel框架go版本

可以参照框架 https://github.com/qit-team/snow
也是按照laravel的架构设计进行设计的go框架。
有很好的的生产实践经验,在公司线上环境有大量的应用,支撑这公司大量的业务场景。经过多年的优化,目前的版本比较稳定。

Validation issue

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.

Guideance : how to return several model associations?

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?

🐛 [Bug] event并发支持

如果是并发场景下,注册事件时,这个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{}
},
},
}
}

Views

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.

✨ [Feature] Specify table prefix

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`
  },
})

✨ [Feature] 优化文件存储sdk

目前市面上大部分存储桶均兼容s3标准,这意味着可以只使用aws s3 sdk就能完成几乎所有存储桶的兼容工作。因此,可以优化移除aliyun oss sdk和tencentcloud cos sdk,缩小打包大小。

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.