forked from gourouting/giligili
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Chengka
committed
Nov 15, 2018
1 parent
c10a8cc
commit 8bab5e1
Showing
547 changed files
with
295,663 additions
and
48 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package conf | ||
|
||
import ( | ||
"github.com/joho/godotenv" | ||
) | ||
|
||
// Init 初始化配置项 | ||
func Init() { | ||
// 从本地读取环境变量 | ||
godotenv.Load() | ||
|
||
// 读取翻译文件 | ||
if err := LoadLocales("conf/locales/zh-cn.yaml"); err != nil { | ||
panic(err) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package util | ||
package conf | ||
|
||
import ( | ||
"io/ioutil" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,54 +1,15 @@ | ||
package main | ||
|
||
import ( | ||
"gin_example/api" | ||
"gin_example/cache" | ||
"gin_example/middleware" | ||
"gin_example/model" | ||
"gin_example/util" | ||
"os" | ||
|
||
"github.com/gin-gonic/gin" | ||
"github.com/joho/godotenv" | ||
"gin_example/conf" | ||
"gin_example/server" | ||
) | ||
|
||
func main() { | ||
godotenv.Load() | ||
|
||
// 从配置文件读取配置 | ||
if err := util.LoadLocales("conf/locales/zh-cn.yaml"); err != nil { | ||
panic(err) | ||
} | ||
|
||
r := gin.Default() | ||
|
||
// 中间件, 顺序不能改 | ||
r.Use(model.Database(os.Getenv("MYSQL_DSN"))) | ||
r.Use(cache.Redis()) | ||
r.Use(middleware.Session(os.Getenv("SESSION_SECRET"))) | ||
r.Use(middleware.Cors()) | ||
r.Use(middleware.CurrentUser()) | ||
|
||
// 路由 | ||
v1 := r.Group("/api/v1") | ||
{ | ||
v1.POST("ping", api.Ping) | ||
|
||
// 用户登录 | ||
v1.POST("user/register", api.UserRegister) | ||
|
||
// 用户登录 | ||
v1.POST("user/login", api.UserLogin) | ||
|
||
// 需要登录保护的 | ||
v1.Use(middleware.AuthRequired()) | ||
{ | ||
// User Routing | ||
v1.GET("user/me", api.UserMe) | ||
v1.DELETE("user/logout", api.UserLogout) | ||
} | ||
} | ||
conf.Init() | ||
|
||
// 监听 | ||
// 装载路由 | ||
r := server.NewRouter() | ||
r.Run(":3000") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package server | ||
|
||
import ( | ||
"gin_example/api" | ||
"gin_example/cache" | ||
"gin_example/middleware" | ||
"gin_example/model" | ||
"os" | ||
|
||
"github.com/gin-gonic/gin" | ||
) | ||
|
||
// NewRouter 路由配置 | ||
func NewRouter() *gin.Engine { | ||
r := gin.Default() | ||
|
||
// 中间件, 顺序不能改 | ||
r.Use(model.Database(os.Getenv("MYSQL_DSN"))) | ||
r.Use(cache.Redis()) | ||
r.Use(middleware.Session(os.Getenv("SESSION_SECRET"))) | ||
r.Use(middleware.Cors()) | ||
r.Use(middleware.CurrentUser()) | ||
|
||
// 路由 | ||
v1 := r.Group("/api/v1") | ||
{ | ||
v1.POST("ping", api.Ping) | ||
|
||
// 用户登录 | ||
v1.POST("user/register", api.UserRegister) | ||
|
||
// 用户登录 | ||
v1.POST("user/login", api.UserLogin) | ||
|
||
// 需要登录保护的 | ||
v1.Use(middleware.AuthRequired()) | ||
{ | ||
// User Routing | ||
v1.GET("user/me", api.UserMe) | ||
v1.DELETE("user/logout", api.UserLogout) | ||
} | ||
} | ||
return r | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.