mirror of
https://forgejo.merr.is/annika/isl-api.git
synced 2025-12-11 14:28:48 -05:00
A Whole Bunch Of Changes
This commit is contained in:
parent
eb45c2fae4
commit
0122fb76f1
11 changed files with 209 additions and 20 deletions
28
main.go
28
main.go
|
|
@ -11,18 +11,42 @@ import (
|
|||
|
||||
"github.com/jackc/pgx/v4"
|
||||
"github.com/julienschmidt/httprouter"
|
||||
"github.com/spf13/viper"
|
||||
)
|
||||
|
||||
var conf *EnvConfigs
|
||||
|
||||
func init() {
|
||||
setupConfig()
|
||||
}
|
||||
|
||||
func main() {
|
||||
deps := dependencies{}
|
||||
deps.initializeDependencies()
|
||||
|
||||
deps.router.HandlerFunc("GET", "/", index)
|
||||
|
||||
err := http.ListenAndServe(":3000", deps.router)
|
||||
err := http.ListenAndServe(fmt.Sprintf(":%v", conf.HttpPort), deps.router)
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
func setupConfig() {
|
||||
viper.AddConfigPath(".")
|
||||
viper.SetConfigName(".env")
|
||||
viper.SetConfigType("env")
|
||||
|
||||
viper.SetEnvPrefix("isl_api")
|
||||
viper.AutomaticEnv()
|
||||
|
||||
if err := viper.ReadInConfig(); err != nil {
|
||||
fmt.Printf("Error reading env file: %v\n", err)
|
||||
}
|
||||
|
||||
if err := viper.Unmarshal(&conf); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
type dependencies struct {
|
||||
router *httprouter.Router
|
||||
postgresConnection *pgx.Conn
|
||||
|
|
@ -37,7 +61,7 @@ func (d *dependencies) initializeDependencies() error {
|
|||
|
||||
d.router = httprouter.New()
|
||||
d.context = context.Background()
|
||||
d.postgresConnection, err = pgx.Connect(d.context, "postgres://isl:development@localhost:5432/isl")
|
||||
d.postgresConnection, err = pgx.Connect(d.context, conf.ConnectionString)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue