Skip to content

Commit

Permalink
Update web-skeleton
Browse files Browse the repository at this point in the history
  • Loading branch information
onanying committed May 5, 2023
1 parent 5c59d6a commit 2a98747
Show file tree
Hide file tree
Showing 11 changed files with 30 additions and 31 deletions.
10 changes: 5 additions & 5 deletions examples/web-skeleton/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,14 +66,14 @@ import (
_ "github.com/mix-go/web-skeleton/configor"
_ "github.com/mix-go/web-skeleton/di"
_ "github.com/mix-go/web-skeleton/dotenv"
"github.com/mix-go/dotenv"
"github.com/mix-go/xutil/xenv"
"github.com/mix-go/xcli"
)

func main() {
xcli.SetName("app").
SetVersion("0.0.0-alpha").
SetDebug(dotenv.Getenv("APP_DEBUG").Bool(false))
SetDebug(xenv.Getenv("APP_DEBUG").Bool(false))
xcli.AddCommand(commands.Commands...).Run()
}
~~~
Expand Down Expand Up @@ -127,7 +127,7 @@ import (
"context"
"fmt"
"github.com/gin-gonic/gin"
"github.com/mix-go/dotenv"
"github.com/mix-go/xutil/xenv"
"github.com/mix-go/web-skeleton/di"
"github.com/mix-go/web-skeleton/routes"
"github.com/mix-go/xcli"
Expand All @@ -150,8 +150,8 @@ func (t *WebCommand) Main() {

logger := di.Logrus()
server := di.Server()
addr := dotenv.Getenv("GIN_ADDR").String(":8080")
mode := dotenv.Getenv("GIN_MODE").String(gin.ReleaseMode)
addr := xenv.Getenv("GIN_ADDR").String(":8080")
mode := xenv.Getenv("GIN_MODE").String(gin.ReleaseMode)

// server
gin.SetMode(mode)
Expand Down
6 changes: 3 additions & 3 deletions examples/web-skeleton/commands/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ import (
"context"
"fmt"
"github.com/gin-gonic/gin"
"github.com/mix-go/dotenv"
"github.com/mix-go/web-skeleton/di"
"github.com/mix-go/web-skeleton/routes"
"github.com/mix-go/xcli"
"github.com/mix-go/xcli/flag"
"github.com/mix-go/xcli/process"
"github.com/mix-go/xutil/xenv"
"os"
"os/signal"
"strings"
Expand All @@ -27,8 +27,8 @@ func (t *WebCommand) Main() {

logger := di.Logrus()
server := di.Server()
addr := dotenv.Getenv("GIN_ADDR").String(":8080")
mode := dotenv.Getenv("GIN_MODE").String(gin.ReleaseMode)
addr := xenv.Getenv("GIN_ADDR").String(":8080")
mode := xenv.Getenv("GIN_MODE").String(gin.ReleaseMode)

// server
gin.SetMode(mode)
Expand Down
4 changes: 2 additions & 2 deletions examples/web-skeleton/config/dotenv/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package dotenv

import (
"fmt"
"github.com/mix-go/dotenv"
"github.com/mix-go/xcli/argv"
"github.com/mix-go/xutil/xenv"
)

func init() {
// Env
if err := dotenv.Load(fmt.Sprintf("%s/../.env", argv.Program().Dir)); err != nil {
if err := xenv.Load(fmt.Sprintf("%s/../.env", argv.Program().Dir)); err != nil {
panic(err)
}
}
10 changes: 5 additions & 5 deletions examples/web-skeleton/di/goredis.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package di

import (
"github.com/mix-go/dotenv"
"github.com/mix-go/xdi"
"github.com/mix-go/xutil/xenv"
"github.com/redis/go-redis/v9"
"time"
)
Expand All @@ -12,10 +12,10 @@ func init() {
Name: "goredis",
New: func() (i interface{}, e error) {
opt := redis.Options{
Addr: dotenv.Getenv("REDIS_ADDR").String(),
Password: dotenv.Getenv("REDIS_PASSWORD").String(),
DB: int(dotenv.Getenv("REDIS_DATABASE").Int64()),
DialTimeout: time.Duration(dotenv.Getenv("REDIS_DIAL_TIMEOUT").Int64(10)) * time.Second,
Addr: xenv.Getenv("REDIS_ADDR").String(),
Password: xenv.Getenv("REDIS_PASSWORD").String(),
DB: int(xenv.Getenv("REDIS_DATABASE").Int64()),
DialTimeout: time.Duration(xenv.Getenv("REDIS_DIAL_TIMEOUT").Int64(10)) * time.Second,
}
return redis.NewClient(&opt), nil
},
Expand Down
4 changes: 2 additions & 2 deletions examples/web-skeleton/di/gorm.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package di

import (
"github.com/mix-go/dotenv"
"github.com/mix-go/xdi"
"github.com/mix-go/xutil/xenv"
"gorm.io/driver/mysql"
"gorm.io/gorm"
)
Expand All @@ -11,7 +11,7 @@ func init() {
obj := xdi.Object{
Name: "gorm",
New: func() (i interface{}, e error) {
return gorm.Open(mysql.Open(dotenv.Getenv("DATABASE_DSN").String()))
return gorm.Open(mysql.Open(xenv.Getenv("DATABASE_DSN").String()))
},
}
if err := xdi.Provide(&obj); err != nil {
Expand Down
10 changes: 5 additions & 5 deletions examples/web-skeleton/di/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ package di
import (
"github.com/go-session/redis"
"github.com/go-session/session"
"github.com/mix-go/dotenv"
"github.com/mix-go/xdi"
"github.com/mix-go/xutil/xenv"
"time"
)

Expand All @@ -13,10 +13,10 @@ func init() {
Name: "session",
New: func() (i interface{}, e error) {
opts := redis.Options{
Addr: dotenv.Getenv("REDIS_ADDR").String(),
Password: dotenv.Getenv("REDIS_PASSWORD").String(),
DB: int(dotenv.Getenv("REDIS_DATABASE").Int64()),
DialTimeout: time.Duration(dotenv.Getenv("REDIS_DIAL_TIMEOUT").Int64(10)) * time.Second,
Addr: xenv.Getenv("REDIS_ADDR").String(),
Password: xenv.Getenv("REDIS_PASSWORD").String(),
DB: int(xenv.Getenv("REDIS_DATABASE").Int64()),
DialTimeout: time.Duration(xenv.Getenv("REDIS_DIAL_TIMEOUT").Int64(10)) * time.Second,
}
opt := redis.NewRedisStore(&opts)
return session.NewManager(session.SetStore(opt)), nil
Expand Down
4 changes: 2 additions & 2 deletions examples/web-skeleton/di/xorm.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,16 @@ package di

import (
_ "github.com/go-sql-driver/mysql"
"github.com/mix-go/dotenv"
"github.com/mix-go/xdi"
"github.com/mix-go/xutil/xenv"
"xorm.io/xorm"
)

func init() {
obj := xdi.Object{
Name: "xorm",
New: func() (i interface{}, e error) {
return xorm.NewEngine("mysql", dotenv.Getenv("DATABASE_DSN").String())
return xorm.NewEngine("mysql", xenv.Getenv("DATABASE_DSN").String())
},
}
if err := xdi.Provide(&obj); err != nil {
Expand Down
4 changes: 2 additions & 2 deletions examples/web-skeleton/di/xsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@ package di
import (
"database/sql"
_ "github.com/go-sql-driver/mysql"
"github.com/mix-go/dotenv"
"github.com/mix-go/xdi"
"github.com/mix-go/xsql"
"github.com/mix-go/xutil/xenv"
)

func init() {
obj := xdi.Object{
Name: "xsql",
New: func() (i interface{}, e error) {
db, err := sql.Open("mysql", dotenv.Getenv("DATABASE_DSN").String())
db, err := sql.Open("mysql", xenv.Getenv("DATABASE_DSN").String())
if err != nil {
return nil, err
}
Expand Down
4 changes: 2 additions & 2 deletions examples/web-skeleton/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ module github.com/mix-go/web-skeleton
go 1.20

replace (
github.com/mix-go/dotenv => ../../src/dotenv
github.com/mix-go/xcli => ../../src/xcli
github.com/mix-go/xdi => ../../src/xdi
github.com/mix-go/xsql => ../../src/xsql
github.com/mix-go/xutil => ../../src/xutil
)

require (
Expand All @@ -16,10 +16,10 @@ require (
github.com/go-sql-driver/mysql v1.7.1
github.com/gorilla/websocket v1.5.0
github.com/jinzhu/configor v1.2.1
github.com/mix-go/dotenv v1.1.15
github.com/mix-go/xcli v1.1.21
github.com/mix-go/xdi v1.1.17
github.com/mix-go/xsql v1.1.11
github.com/mix-go/xutil v1.1.6
github.com/redis/go-redis/v9 v9.0.4
github.com/sirupsen/logrus v1.9.0
github.com/spf13/viper v1.15.0
Expand Down
1 change: 0 additions & 1 deletion examples/web-skeleton/go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,6 @@ github.com/jinzhu/inflection v1.0.0/go.mod h1:h+uFLlag+Qp1Va5pdKtLDYj+kHp5pxUVkr
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/jmespath/go-jmespath v0.0.0-20180206201540-c2b33e8439af/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k=
github.com/joho/godotenv v1.3.0/go.mod h1:7hK45KPybAkOC6peb+G5yklZfMxEjkZhHbwpqxOKXbg=
github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0=
github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
Expand Down
4 changes: 2 additions & 2 deletions examples/web-skeleton/main.go
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package main

import (
"github.com/mix-go/dotenv"
"github.com/mix-go/web-skeleton/commands"
_ "github.com/mix-go/web-skeleton/config/configor"
_ "github.com/mix-go/web-skeleton/config/dotenv"
_ "github.com/mix-go/web-skeleton/di"
"github.com/mix-go/xcli"
"github.com/mix-go/xutil/xenv"
)

func main() {
xcli.SetName("app").
SetVersion("0.0.0-alpha").
SetDebug(dotenv.Getenv("APP_DEBUG").Bool(false))
SetDebug(xenv.Getenv("APP_DEBUG").Bool(false))
xcli.AddCommand(commands.Commands...).Run()
}

0 comments on commit 2a98747

Please sign in to comment.