-
-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #5 from dmalusev/feat/uber-fx
Feat/uber fx
- Loading branch information
Showing
26 changed files
with
160 additions
and
1,189 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 |
---|---|---|
@@ -1,29 +1,44 @@ | ||
package commands | ||
|
||
import ( | ||
"time" | ||
|
||
"github.com/spf13/cobra" | ||
"go.uber.org/fx" | ||
|
||
"github.com/dmalusev/uberfx-common/configfx" | ||
"github.com/dmalusev/uberfx-common/fiber/fiberfx" | ||
"github.com/dmalusev/uberfx-common/loggerfx" | ||
|
||
"github.com/BrosSquad/GoFiber-Boilerplate/app/container" | ||
"github.com/BrosSquad/GoFiber-Boilerplate/app/http" | ||
"github.com/BrosSquad/GoFiber-Boilerplate/core/constants" | ||
corehttp "github.com/BrosSquad/GoFiber-Boilerplate/core/http" | ||
"github.com/dmalusev/GoFiber-Boilerplate/app/config" | ||
"github.com/dmalusev/GoFiber-Boilerplate/app/constants" | ||
"github.com/dmalusev/GoFiber-Boilerplate/app/handlers" | ||
) | ||
|
||
func loggerSink(cfg *config.Logging) loggerfx.Sink { | ||
return loggerfx.Sink{ | ||
Level: cfg.Level, | ||
Type: loggerfx.Stdout, | ||
PrettyPrint: cfg.PrettyPrint, | ||
} | ||
} | ||
|
||
func Serve() *cobra.Command { | ||
return &cobra.Command{ | ||
Use: "serve", | ||
RunE: func(cmd *cobra.Command, args []string) error { | ||
ctx := cmd.Context() | ||
di := ctx.Value(constants.ContainerContextKey).(*container.Container) | ||
app := http.CreateApplication(ctx, di, true) | ||
RunE: func(_ *cobra.Command, _ []string) error { | ||
cfg, err := configfx.New[config.Config](constants.AppName) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
cfg := di.GetConfig().HTTP | ||
go corehttp.RunServer(cfg.Addr, cfg.Port, app) | ||
app := fx.New( | ||
configfx.Module(cfg), | ||
loggerfx.Module(loggerSink(&cfg.Logging)), | ||
fiberfx.App(constants.AppName, cfg.App.FiberInfo, handlers.Handlers()), | ||
fiberfx.RunApp(cfg.HTTP.Addr, constants.AppName, cfg.HTTP.ShutdownTimeout), | ||
) | ||
|
||
<-ctx.Done() | ||
return app.ShutdownWithTimeout(10 * time.Second) | ||
app.Run() | ||
return nil | ||
}, | ||
} | ||
} |
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,55 +1,17 @@ | ||
package config | ||
|
||
import ( | ||
"github.com/spf13/viper" | ||
|
||
"github.com/BrosSquad/GoFiber-Boilerplate/app/constants" | ||
utilsconfig "github.com/nano-interactive/go-utils/config" | ||
) | ||
|
||
type ( | ||
App struct { | ||
FiberInfo bool `mapstructure:"fiber_info" json:"fiber_info" yaml:"fiber_info"` | ||
} | ||
Logging struct { | ||
Level string `mapstructure:"level" json:"level" yaml:"level"` | ||
PrettyPrint bool `mapstructure:"pretty_print" json:"pretty_print" yaml:"pretty_print"` | ||
} | ||
|
||
HTTP struct { | ||
Addr string `mapstructure:"addr" json:"addr" yaml:"addr"` | ||
Port int `mapstructure:"port" json:"port" yaml:"port"` | ||
} | ||
|
||
Config struct { | ||
Logging Logging `mapstructure:"logging" json:"logging" yaml:"logging"` | ||
HTTP HTTP `mapstructure:"http" json:"http" yaml:"http"` | ||
App App `mapstructure:"app" json:"app" yaml:"app"` | ||
} | ||
) | ||
|
||
func New() (Config, error) { | ||
cfg := utilsconfig.Config{ | ||
ProjectName: constants.AppName, | ||
Name: "config", | ||
Type: "yaml", | ||
Paths: []string{ | ||
"$XDG_CONFIG_HOME/" + constants.AppName, | ||
"/etc/" + constants.AppName, | ||
".", | ||
}, | ||
} | ||
|
||
v, err := utilsconfig.NewWithModifier(cfg) | ||
if err != nil { | ||
return Config{}, err | ||
} | ||
|
||
return NewWithViper(v) | ||
} | ||
|
||
func NewWithViper(v *viper.Viper) (Config, error) { | ||
c := Config{} | ||
|
||
if err := v.Unmarshal(&c); err != nil { | ||
return Config{}, err | ||
} | ||
|
||
return c, nil | ||
} |
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,10 @@ | ||
package config | ||
|
||
import ( | ||
"time" | ||
) | ||
|
||
type HTTP struct { | ||
Addr string `mapstructure:"addr" json:"addr" yaml:"addr"` | ||
ShutdownTimeout time.Duration `mapstructure:"shutdown_timeout" json:"shutdown_timeout" yaml:"shutdown_timeout"` | ||
} |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,13 @@ | ||
package handlers | ||
|
||
import ( | ||
"github.com/dmalusev/GoFiber-Boilerplate/app/handlers/helloworld" | ||
"github.com/dmalusev/uberfx-common/fiber/fiberfx" | ||
) | ||
|
||
func Handlers() fiberfx.RoutesFx { | ||
return fiberfx.Routes( | ||
fiberfx.WithRoutes(fiberfx.Get("/", helloworld.HelloWorld)), | ||
fiberfx.WithPrefix("/"), | ||
) | ||
} |
File renamed without changes.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,3 +1,12 @@ | ||
app: | ||
fiber_info: true | ||
|
||
http: | ||
addr: '0.0.0.0' | ||
port: 8080 | ||
addr: '0.0.0.0:8080' | ||
shutdown_timeout: 1s | ||
profiler_addr: '0.0.0.0:5000' | ||
|
||
|
||
logging: | ||
level: debug | ||
pretty_print: true |
Oops, something went wrong.