Skip to content

Commit c3f0c54

Browse files
committed
Init structure projetc
1 parent 91c10f4 commit c3f0c54

File tree

5 files changed

+602
-0
lines changed

5 files changed

+602
-0
lines changed

cmd/server/.env

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
DB_DRIVER=mysql
2+
DB_HOST=localhost
3+
DB_PORT=3306
4+
DB_USER=skeleton
5+
DB_PASS=skeleton
6+
DB_NAME=skeleton
7+
WS_PORT=9090
8+
JWT_SECRET=screte
9+
JWT_EXPIRE_IN=300

cmd/server/main.go

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
package main
2+
3+
func main() {
4+
}

configs/config.go

+44
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package configs
2+
3+
import (
4+
"github.com/go-chi/jwtauth"
5+
"github.com/spf13/viper"
6+
)
7+
8+
var cfg *conf
9+
10+
type conf struct {
11+
DBDriver string `mapstructure:"DB_DRIVER"`
12+
DBHost string `mapstructure:"DB_HOST"`
13+
DBPort string `mapstructure:"DB_PORT"`
14+
DBUser string `mapstructure:"DB_USER"`
15+
DBPass string `mapstructure:"DB_PASS"`
16+
DBName string `mapstructure:"DB_NAME"`
17+
WSPort string `mapstructure:"WS_PORT"`
18+
JWTSecret string `mapstructure:"JWT_SECRET"`
19+
JWTExpireIn int `mapstructure:"JWT_EXPIRE_IN"`
20+
TokenAuth *jwtauth.JWTAuth
21+
}
22+
23+
// Executada antes da função main
24+
func init() {
25+
26+
}
27+
28+
func LoadConfig(path string) (*conf, error) {
29+
viper.SetConfigName("app_config")
30+
viper.SetConfigType("env")
31+
viper.AddConfigPath(path)
32+
viper.SetConfigFile(".env")
33+
viper.AutomaticEnv()
34+
err := viper.ReadInConfig()
35+
if err != nil {
36+
panic(err)
37+
}
38+
err = viper.Unmarshal(&cfg)
39+
if err != nil {
40+
panic(err)
41+
}
42+
cfg.TokenAuth = jwtauth.New("HS256", []byte(cfg.JWTSecret), nil)
43+
return cfg, nil
44+
}

go.mod

+35
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
module github.com/pamelaborges/skeleton-api-go
2+
3+
go 1.20
4+
5+
require (
6+
github.com/fsnotify/fsnotify v1.6.0 // indirect
7+
github.com/go-chi/jwtauth v1.2.0 // indirect
8+
github.com/goccy/go-json v0.3.5 // indirect
9+
github.com/hashicorp/hcl v1.0.0 // indirect
10+
github.com/lestrrat-go/backoff/v2 v2.0.7 // indirect
11+
github.com/lestrrat-go/httpcc v1.0.0 // indirect
12+
github.com/lestrrat-go/iter v1.0.0 // indirect
13+
github.com/lestrrat-go/jwx v1.1.0 // indirect
14+
github.com/lestrrat-go/option v1.0.0 // indirect
15+
github.com/magiconair/properties v1.8.7 // indirect
16+
github.com/mitchellh/mapstructure v1.5.0 // indirect
17+
github.com/pelletier/go-toml/v2 v2.1.0 // indirect
18+
github.com/pkg/errors v0.9.1 // indirect
19+
github.com/sagikazarmark/locafero v0.3.0 // indirect
20+
github.com/sagikazarmark/slog-shim v0.1.0 // indirect
21+
github.com/sourcegraph/conc v0.3.0 // indirect
22+
github.com/spf13/afero v1.10.0 // indirect
23+
github.com/spf13/cast v1.5.1 // indirect
24+
github.com/spf13/pflag v1.0.5 // indirect
25+
github.com/spf13/viper v1.17.0 // indirect
26+
github.com/subosito/gotenv v1.6.0 // indirect
27+
go.uber.org/atomic v1.9.0 // indirect
28+
go.uber.org/multierr v1.9.0 // indirect
29+
golang.org/x/crypto v0.13.0 // indirect
30+
golang.org/x/exp v0.0.0-20230905200255-921286631fa9 // indirect
31+
golang.org/x/sys v0.12.0 // indirect
32+
golang.org/x/text v0.13.0 // indirect
33+
gopkg.in/ini.v1 v1.67.0 // indirect
34+
gopkg.in/yaml.v3 v3.0.1 // indirect
35+
)

0 commit comments

Comments
 (0)