Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade v1.0.0 #2

Merged
merged 10 commits into from
Oct 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 13 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<p align="center"><img src="https://goravel.s3.us-east-2.amazonaws.com/goravel-word.png" width="300"></p>
<!-- <p align="center"><img src="https://goravel.s3.us-east-2.amazonaws.com/goravel-word.png" width="300"></p> -->

English | [中文](README_cn.md)
English | [中文](../zh/README.md)

# About Goravel
## About Goravel

Goravel is a web application framework with complete functions and good scalability. As a starting scaffolding to help
Golang developers quickly build their own applications.
Expand All @@ -15,36 +15,30 @@ Golang developers quickly build their own applications.
- [x] Migrate
- [x] Logger
- [x] Cache
- [x] gRPC
- [x] Grpc
- [x] Artisan Console
- [x] Task Scheduling
- [x] Queue
- [x] Event
- [ ] Mail
- [x] Mail
- [x] Mock

## Documentation

Online documentation [https://www.goravel.dev/en](https://www.goravel.dev/en)

Documentation repository [https://github.com/goravel/docs](https://github.com/goravel/docs)
> To optimize the documentation, please submit a PR to the documentation repository [https://github.com/goravel/docs](https://github.com/goravel/docs)

## Grateful
## Group

The framework refers to the design ideas of Laravel;
Welcome more exchanges in Discord.

The core functions use well-known Golang components, including but not limited to:
[spf13/viper](https://github.com/spf13/viper) ,
[gin-gonic/gin](https://github.com/gin-gonic/gin) ,
[go-redis/redis](https://github.com/go-redis/redis) ,
[urfave/cli](https://github.com/urfave/cli) ,
[sirupsen/logrus](https://github.com/sirupsen/logrus) ,
[robfig/cron](https://github.com/robfig/cron) ,
[go-gorm/gorm](https://github.com/go-gorm/gorm) ;
[https://discord.gg/cFc5csczzS](https://discord.gg/cFc5csczzS)

The documentation refers to the content of [Laravel](https://laravel.com/docs/8.x);
## Tribute Laravel

Tribute to them!
Goravel and Laravel remain highly consistent, let PHPer play Golang happily without learning a new framework!

## License

The Goravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).
The Goravel framework is open-sourced software licensed under the [MIT license](https://opensource.org/licenses/MIT).
34 changes: 16 additions & 18 deletions README_cn.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
<p align="center"><img src="https://goravel.s3.us-east-2.amazonaws.com/goravel-word.png" width="300"></p>
<!-- <p align="center"><img src="https://goravel.s3.us-east-2.amazonaws.com/goravel-word.png" width="300"></p> -->

[English](README.md) | 中文
[English](../README.md) | 中文

# 关于 Goravel

Goravel 是一个功能完备、具有良好扩展能力的 Web 应用程序框架。 作为一个起始脚手架帮助 Golang 开发者快速构建自己的应用。
Goravel 是一个功能完备、具有良好扩展能力的 Web 应用程序框架。作为一个起始脚手架帮助 Golang 开发者快速构建自己的应用。

## 主要功能

Expand All @@ -14,35 +14,33 @@ Goravel 是一个功能完备、具有良好扩展能力的 Web 应用程序框
- [x] 数据库迁移
- [x] 日志
- [x] 缓存
- [x] gRPC
- [x] Grpc
- [x] Artisan 命令行
- [x] 任务调度
- [x] 队列
- [x] 事件系统
- [ ] 邮件
- [x] 邮件
- [x] Mock

## 文档

在线文档 [https://www.goravel.dev/cn](https://www.goravel.dev/cn)

文档仓库 [https://github.com/goravel/docs](https://github.com/goravel/docs)
> 优化文档,请提交 PR 至文档仓库 [https://github.com/goravel/docs](https://github.com/goravel/docs)

## 感谢
## Group

框架参考了 [Laravel](https://github.com/laravel/laravel) 的设计思想;
欢迎在 Discord 中更多交流。

核心功能使用知名的 Golang 组件, 包括但不限于:
[spf13/viper](https://github.com/spf13/viper) 、
[gin-gonic/gin](https://github.com/gin-gonic/gin) 、
[go-redis/redis](https://github.com/go-redis/redis) 、
[urfave/cli](https://github.com/urfave/cli) 、
[sirupsen/logrus](https://github.com/sirupsen/logrus) 、
[robfig/cron](https://github.com/robfig/cron) 、
[go-gorm/gorm](https://github.com/go-gorm/gorm) ;
[https://discord.gg/cFc5csczzS](https://discord.gg/cFc5csczzS)

文档参考了 [LearnKu 社区](https://learnku.com/) 的 [Laravel 中文文档](https://learnku.com/docs/laravel/8.x/structure/9356) ;
微信入群

向他们致敬!
![](https://user-images.githubusercontent.com/24771476/194740900-cee4aa43-7c22-42b6-ada9-42bc160cd797.JPG)

## 致敬 Laravel

框架与 [Laravel](https://github.com/laravel/laravel) 保持高度一致,让 PHPer 不用学习新的框架,也可以愉快的玩转 Golang!

## 开源许可

Expand Down
12 changes: 8 additions & 4 deletions cache/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@ package cache

import (
"context"
"fmt"
"runtime/debug"

"github.com/go-redis/redis/v8"
"github.com/gookit/color"
"github.com/goravel/framework/contracts/cache"
"github.com/goravel/framework/support/facades"
"github.com/goravel/framework/facades"
)

type Application struct {
Expand All @@ -24,12 +26,12 @@ func (app *Application) Init() cache.Store {
if custom, ok := facades.Config.Get("cache.stores." + defaultStore + ".via").(cache.Store); ok {
return custom
}
facades.Log.Warnf("%s doesn't impletement contracts/cache/store", defaultStore)
color.Redln("%s doesn't implement contracts/cache/store", defaultStore)

return store
}

facades.Log.Warnf("Not supported cache store: %s", defaultStore)
color.Redln("Not supported cache store: %s", defaultStore)

return store
}
Expand All @@ -54,7 +56,9 @@ func (app *Application) createRedisDriver() *Redis {

pong, err := client.Ping(context.Background()).Result()
if err != nil {
facades.Log.Warnf("Failed to link redis:%s, %s\n%+v", pong, err, string(debug.Stack()))
color.Redln(fmt.Sprintf("Failed to link redis:%s, %s\n%+v", pong, err, string(debug.Stack())))

return nil
}

return &Redis{
Expand Down
6 changes: 3 additions & 3 deletions cache/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (

"github.com/goravel/framework/config"
"github.com/goravel/framework/console"
"github.com/goravel/framework/support/facades"
testing2 "github.com/goravel/framework/support/testing"
"github.com/goravel/framework/facades"
"github.com/goravel/framework/testing/file"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -43,7 +43,7 @@ func TestClearCommand(t *testing.T) {
}

func initConfig() {
testing2.CreateEnv()
file.CreateEnv()
configServiceProvider := config.ServiceProvider{}
configServiceProvider.Register()

Expand Down
10 changes: 5 additions & 5 deletions cache/console/clear_command.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package console
import (
"github.com/gookit/color"
"github.com/goravel/framework/contracts/console"
"github.com/goravel/framework/support/facades"
"github.com/urfave/cli/v2"
"github.com/goravel/framework/contracts/console/command"
"github.com/goravel/framework/facades"
)

type ClearCommand struct {
Expand All @@ -21,14 +21,14 @@ func (receiver *ClearCommand) Description() string {
}

//Extend The console command extend.
func (receiver *ClearCommand) Extend() console.CommandExtend {
return console.CommandExtend{
func (receiver *ClearCommand) Extend() command.Extend {
return command.Extend{
Category: "cache",
}
}

//Handle Execute the console command.
func (receiver *ClearCommand) Handle(c *cli.Context) error {
func (receiver *ClearCommand) Handle(ctx console.Context) error {
res := facades.Cache.Flush()

if res {
Expand Down
13 changes: 5 additions & 8 deletions cache/service_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,24 +3,21 @@ package cache
import (
"github.com/goravel/framework/cache/console"
console2 "github.com/goravel/framework/contracts/console"
"github.com/goravel/framework/support/facades"
"github.com/goravel/framework/facades"
)

type ServiceProvider struct {
}

//Boot Bootstrap any application services after register.
func (database *ServiceProvider) Boot() {
database.registerCommands()
}

//Register any application services.
func (database *ServiceProvider) Register() {
app := Application{}
facades.Cache = app.Init()
}

//registerCommands Register the given commands.
func (database *ServiceProvider) Boot() {
database.registerCommands()
}

func (database *ServiceProvider) registerCommands() {
facades.Artisan.Register([]console2.Command{
&console.ClearCommand{},
Expand Down
53 changes: 44 additions & 9 deletions config/application.go
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package config

import (
"github.com/goravel/framework/support/testing"
"github.com/spf13/cast"
"github.com/spf13/viper"

"github.com/goravel/framework/testing"
)

type Application struct {
Expand All @@ -29,39 +30,73 @@ func (app *Application) Init() *Application {

//Env Get config from env.
func (app *Application) Env(envName string, defaultValue ...interface{}) interface{} {
if len(defaultValue) > 0 {
return app.Get(envName, defaultValue[0])
value := app.Get(envName, defaultValue...)
if cast.ToString(value) == "" {
if len(defaultValue) > 0 {
return defaultValue[0]
}

return nil
}
return app.Get(envName)

return value
}

//Add Add config to application.
//Add config to application.
func (app *Application) Add(name string, configuration map[string]interface{}) {
app.vip.Set(name, configuration)
}

//Get Get config from application.
//Get config from application.
func (app *Application) Get(path string, defaultValue ...interface{}) interface{} {
if !app.vip.IsSet(path) {
if len(defaultValue) > 0 {
return defaultValue[0]
}
return nil
}

return app.vip.Get(path)
}

//GetString Get string type config from application.
func (app *Application) GetString(path string, defaultValue ...interface{}) string {
return cast.ToString(app.Get(path, defaultValue...))
value := cast.ToString(app.Get(path, defaultValue...))
if value == "" {
if len(defaultValue) > 0 {
return defaultValue[0].(string)
}

return ""
}

return value
}

//GetInt Get int type config from application.
func (app *Application) GetInt(path string, defaultValue ...interface{}) int {
return cast.ToInt(app.Get(path, defaultValue...))
value := app.Get(path, defaultValue...)
if cast.ToString(value) == "" {
if len(defaultValue) > 0 {
return defaultValue[0].(int)
}

return 0
}

return cast.ToInt(value)
}

//GetBool Get bool type config from application.
func (app *Application) GetBool(path string, defaultValue ...interface{}) bool {
return cast.ToBool(app.Get(path, defaultValue...))
value := app.Get(path, defaultValue...)
if cast.ToString(value) == "" {
if len(defaultValue) > 0 {
return defaultValue[0].(bool)
}

return false
}

return cast.ToBool(value)
}
4 changes: 2 additions & 2 deletions config/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"os"
"testing"

testing2 "github.com/goravel/framework/support/testing"
"github.com/goravel/framework/testing/file"
"github.com/stretchr/testify/assert"
)

func TestInit(t *testing.T) {
err := testing2.CreateEnv()
err := file.CreateEnv()
assert.Nil(t, err)
assert.NotPanics(t, func() {
app := Application{}
Expand Down
12 changes: 5 additions & 7 deletions config/service_provider.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
package config

import (
"github.com/goravel/framework/support/facades"
"github.com/goravel/framework/facades"
)

type ServiceProvider struct {
}

//Boot Bootstrap any application services after register.
func (config *ServiceProvider) Boot() {

}

//Register Register any application services.
func (config *ServiceProvider) Register() {
app := Application{}
facades.Config = app.Init()
}

func (config *ServiceProvider) Boot() {

}
Loading