fix: refactor layout init
This commit is contained in:
@@ -0,0 +1,7 @@
|
||||
package staffrepository
|
||||
|
||||
func (ur *StaffRepository) Update() error {
|
||||
// if err := ur.DB.Update(column string, value interface{})
|
||||
|
||||
return nil
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
package contenthttp
|
||||
|
||||
import "go.uber.org/fx"
|
||||
|
||||
var Module = fx.Module("content-api", fx.Invoke())
|
||||
@@ -8,6 +8,7 @@ import (
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/ardeman/project-legalgo-go/config"
|
||||
"github.com/go-chi/chi/v5"
|
||||
"github.com/sirupsen/logrus"
|
||||
"golang.org/x/sync/errgroup"
|
||||
@@ -28,14 +29,14 @@ func Router(apiRouter chi.Router) {
|
||||
group, groupCtx := errgroup.WithContext(mainCtx)
|
||||
|
||||
group.Go(func() error {
|
||||
logrus.Infof("Listening to port %d", APP_PORT)
|
||||
logrus.Infof("Listening to port %d", config.APP_PORT)
|
||||
return svr.ListenAndServe()
|
||||
})
|
||||
|
||||
group.Go(func() error {
|
||||
<-groupCtx.Done()
|
||||
|
||||
ctxTimeout, cancel := context.WithTimeout(mainCtx, GRACEFULL_TIMEOUT*time.Second)
|
||||
ctxTimeout, cancel := context.WithTimeout(mainCtx, time.Duration(config.GRACEFULL_TIMEOUT)*time.Second)
|
||||
defer cancel()
|
||||
|
||||
svr.Shutdown(ctxTimeout)
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
package newsdomain
|
||||
|
||||
type News struct {
|
||||
Title string `json:"title"`
|
||||
Content string `json:"content"`
|
||||
FeaturedImage string `json:"featured_image"`
|
||||
Tags []string `json:"tags"`
|
||||
Categories []string `json:"categories"`
|
||||
IsPremium bool `json:"is_premium"`
|
||||
Slug string `json:"slug"`
|
||||
Author string `json:"author"`
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
package utils
|
||||
|
||||
import (
|
||||
"os"
|
||||
"reflect"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
func GetOrDefault[T any](key string, defaultValue T) T {
|
||||
value, exist := os.LookupEnv(key)
|
||||
|
||||
if !exist {
|
||||
return defaultValue
|
||||
}
|
||||
|
||||
var valueInstance T
|
||||
kind := reflect.ValueOf(valueInstance).Kind()
|
||||
switch kind {
|
||||
case reflect.String:
|
||||
return any(value).(T)
|
||||
case reflect.Int:
|
||||
if val, err := strconv.Atoi(value); err == nil {
|
||||
return any(val).(T)
|
||||
}
|
||||
return any(defaultValue).(T)
|
||||
case reflect.Bool:
|
||||
if val, err := strconv.ParseBool(value); err == nil {
|
||||
return any(val).(T)
|
||||
}
|
||||
return any(defaultValue).(T)
|
||||
default:
|
||||
return any(defaultValue).(T)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user