Skip to content

Commit

Permalink
update go-service-base/util to v1.1.0 and use go-service-base/logger …
Browse files Browse the repository at this point in the history
…v0.2.0 and go-service-base/config-hdl v0.1.0
  • Loading branch information
y-du committed Aug 1, 2024
1 parent a312679 commit 861b742
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 21 deletions.
6 changes: 4 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,19 @@ go 1.22.0

require (
github.com/SENERGY-Platform/gin-middleware v0.4.3
github.com/SENERGY-Platform/go-service-base/config-hdl v0.1.0
github.com/SENERGY-Platform/go-service-base/context-hdl v0.0.3
github.com/SENERGY-Platform/go-service-base/logger v0.2.0
github.com/SENERGY-Platform/go-service-base/srv-info-hdl v0.0.3
github.com/SENERGY-Platform/go-service-base/srv-info-hdl/lib v0.0.2
github.com/SENERGY-Platform/go-service-base/util v0.14.1
github.com/SENERGY-Platform/go-service-base/util v1.1.0
github.com/SENERGY-Platform/go-service-base/watchdog v0.4.2
github.com/SENERGY-Platform/mgw-auth-service/lib v0.0.0-00010101000000-000000000000
github.com/gin-contrib/requestid v1.0.2
github.com/gin-gonic/gin v1.10.0
github.com/google/uuid v1.6.0
github.com/ory/kratos-client-go v1.2.1
github.com/y-du/go-log-level v0.2.4
github.com/y-du/go-log-level v1.0.0
)

require (
Expand Down
12 changes: 8 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
github.com/SENERGY-Platform/gin-middleware v0.4.3 h1:ox8i2+rFuHJAd/oKdHuayz2HHSlWfRQqAituwNVHRfA=
github.com/SENERGY-Platform/gin-middleware v0.4.3/go.mod h1:TNjnCZSYjhYd+Rq0yu9FfYd2ct2sJK59wHtwA9Fog7o=
github.com/SENERGY-Platform/go-service-base/config-hdl v0.1.0 h1:0jJWtujKb4Hr1HRXmmCST011ZcpLyt7/SlV00pwUN8g=
github.com/SENERGY-Platform/go-service-base/config-hdl v0.1.0/go.mod h1:pQjV0KfwCM91I7LSTUg9t4tgSNSHKiefH/O5+J5N8z8=
github.com/SENERGY-Platform/go-service-base/context-hdl v0.0.3 h1:deqgKAtt5NSbIssrkJMm3btQ8IttRbencDshOzbWle4=
github.com/SENERGY-Platform/go-service-base/context-hdl v0.0.3/go.mod h1:5VMJNUMFo9tzNHFUx+RcPAIpimYreqhKN1XvTA3QdnE=
github.com/SENERGY-Platform/go-service-base/logger v0.2.0 h1:O8aGx+JJVyV6AxfcxIVHH6lyXeRMleui6L9J9JEI3vM=
github.com/SENERGY-Platform/go-service-base/logger v0.2.0/go.mod h1:4g66GXZ3LBa0XSB2eSdDJtqLkm2xuju4qzc77Cf2Nhc=
github.com/SENERGY-Platform/go-service-base/srv-info-hdl v0.0.3 h1:/A2bZFh3Aol1uXuR0YAxVB4POcRSshBIG2qfIEIW+gg=
github.com/SENERGY-Platform/go-service-base/srv-info-hdl v0.0.3/go.mod h1:Go9v41HF8FYnGr40jnzl8pfT7xvls3HXinJOiPj4Yh0=
github.com/SENERGY-Platform/go-service-base/srv-info-hdl/lib v0.0.2 h1:Bcdxt7i3DGGvlwS6U3NY9eGJjiPuv3ZpbMwebEUV+nE=
github.com/SENERGY-Platform/go-service-base/srv-info-hdl/lib v0.0.2/go.mod h1:vcvyLaSoZsScGQ8K/OuJxlANTs5FPozsLvPzFUZgiVM=
github.com/SENERGY-Platform/go-service-base/util v0.14.1 h1:Dy5JIVIWnVDiq5//RBGRF0JKAIG4TaqFsa80wtlfMKE=
github.com/SENERGY-Platform/go-service-base/util v0.14.1/go.mod h1:8W+F6aCpUnrP6SsxVStk+0MZqF71wJADGySKmZzkFBM=
github.com/SENERGY-Platform/go-service-base/util v1.1.0 h1:dsfWSfv+k0xr1kgasjIfw1UrvYL2G4QUmMvEwwNJi7c=
github.com/SENERGY-Platform/go-service-base/util v1.1.0/go.mod h1:/gs/BaaSNwC+jbjsSgWDPoeMhfq8uJsf0WVQtyjP+wM=
github.com/SENERGY-Platform/go-service-base/watchdog v0.4.2 h1:y88XOKuUbJdwvtDgUj9h2vTI+gwZvyB1giwoMvStrGI=
github.com/SENERGY-Platform/go-service-base/watchdog v0.4.2/go.mod h1:g3L+QFVvGghsnOsB4V1dkoq4egiFGUoD1x83g2H6Imw=
github.com/bytedance/sonic v1.11.6 h1:oUp34TzMlL+OY1OUWxHqsdkgC/Zfc85zGqw9siXjrc0=
Expand Down Expand Up @@ -83,8 +87,8 @@ github.com/ugorji/go/codec v1.2.12 h1:9LC83zGrHhuUA9l16C9AHXAqEV/2wBQ4nkvumAE65E
github.com/ugorji/go/codec v1.2.12/go.mod h1:UNopzCgEMSXjBc6AOMqYvWC1ktqTAfzJZUZgYf6w6lg=
github.com/y-du/go-env-loader v0.5.2 h1:LxubTfx7zl1VpBNzUQidSp3yub3/7mxMg63QSuRlhd4=
github.com/y-du/go-env-loader v0.5.2/go.mod h1:QBaFGtrTdp4eiMUjg9UFf1F3TzbEbUhWDeHYyEsqs8Y=
github.com/y-du/go-log-level v0.2.4 h1:COCFNczF7b7yd5leEAVMnO6OYaLZVu9lsrk68Qln6t4=
github.com/y-du/go-log-level v0.2.4/go.mod h1:lhCvJlDCuSC9GfmtVDXuXc7lbbAd8igxl58qK8SjPX8=
github.com/y-du/go-log-level v1.0.0 h1:Q4Ffqxmf/tn9DBbOMwcjEGkWwQyYMwPn+FR06k5HJ70=
github.com/y-du/go-log-level v1.0.0/go.mod h1:lhCvJlDCuSC9GfmtVDXuXc7lbbAd8igxl58qK8SjPX8=
golang.org/x/arch v0.0.0-20210923205945-b76863e36670/go.mod h1:5om86z9Hs0C8fWVUuoMHwpExlXzs5Tkyp9hOrfG7pp8=
golang.org/x/arch v0.8.0 h1:3wRIsP3pM4yUptoR96otTUOXI367OS0+c9eeRi9doIc=
golang.org/x/arch v0.8.0/go.mod h1:FEVrYAQjsQXMVJ1nsMoVVXPZg6p2JE2mx8psSWTDQys=
Expand Down
5 changes: 3 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"errors"
"fmt"
"github.com/SENERGY-Platform/gin-middleware"
sb_logger "github.com/SENERGY-Platform/go-service-base/logger"
srv_info_hdl "github.com/SENERGY-Platform/go-service-base/srv-info-hdl"
sb_util "github.com/SENERGY-Platform/go-service-base/util"
"github.com/SENERGY-Platform/go-service-base/watchdog"
Expand Down Expand Up @@ -63,7 +64,7 @@ func main() {
logFile, err := util.InitLogger(config.Logger)
if err != nil {
_, _ = fmt.Fprintln(os.Stderr, err)
var logFileError *sb_util.LogFileError
var logFileError *sb_logger.LogFileError
if errors.As(err, &logFileError) {
ec = 1
return
Expand Down Expand Up @@ -143,7 +144,7 @@ func main() {
return nil
})

mApi.CreateInitialIdentity(diCtx, config.InitIdentity.User, config.InitIdentity.Secret.String(), time.Second*5, 10)
mApi.CreateInitialIdentity(diCtx, config.InitIdentity.User, config.InitIdentity.Secret.Value(), time.Second*5, 10)

go func() {
defer srvCF()
Expand Down
31 changes: 21 additions & 10 deletions util/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@
package util

import (
sb_util "github.com/SENERGY-Platform/go-service-base/util"
"github.com/SENERGY-Platform/go-service-base/config-hdl"
cfg_types "github.com/SENERGY-Platform/go-service-base/config-hdl/types"
"github.com/y-du/go-log-level/level"
)

Expand All @@ -27,22 +28,32 @@ type HttpClientConfig struct {
}

type InitIdentityConfig struct {
User string `json:"user" env_var:"II_USER"`
Secret sb_util.SecretString `json:"secret" env_var:"II_SECRET"`
User string `json:"user" env_var:"II_USER"`
Secret cfg_types.Secret `json:"secret" env_var:"II_SECRET"`
}

type LoggerConfig struct {
Level level.Level `json:"level" env_var:"LOGGER_LEVEL"`
Utc bool `json:"utc" env_var:"LOGGER_UTC"`
Path string `json:"path" env_var:"LOGGER_PATH"`
FileName string `json:"file_name" env_var:"LOGGER_FILE_NAME"`
Terminal bool `json:"terminal" env_var:"LOGGER_TERMINAL"`
Microseconds bool `json:"microseconds" env_var:"LOGGER_MICROSECONDS"`
Prefix string `json:"prefix" env_var:"LOGGER_PREFIX"`
}

type Config struct {
ServerPort uint `json:"server_port" env_var:"SERVER_PORT"`
Logger sb_util.LoggerConfig `json:"logger" env_var:"LOGGER_CONFIG"`
HttpClient HttpClientConfig `json:"http_client" env_var:"HTTP_CLIENT_CONFIG"`
CSDefDuration int64 `json:"cs_def_duration" env_var:"CS_DEF_DURATION"`
InitIdentity InitIdentityConfig `json:"init_identity" env_var:"INIT_IDENTITY"`
ServerPort uint `json:"server_port" env_var:"SERVER_PORT"`
Logger LoggerConfig `json:"logger" env_var:"LOGGER_CONFIG"`
HttpClient HttpClientConfig `json:"http_client" env_var:"HTTP_CLIENT_CONFIG"`
CSDefDuration int64 `json:"cs_def_duration" env_var:"CS_DEF_DURATION"`
InitIdentity InitIdentityConfig `json:"init_identity" env_var:"INIT_IDENTITY"`
}

func NewConfig(path string) (*Config, error) {
cfg := Config{
ServerPort: 80,
Logger: sb_util.LoggerConfig{
Logger: LoggerConfig{
Level: level.Warning,
Utc: true,
Microseconds: true,
Expand All @@ -54,6 +65,6 @@ func NewConfig(path string) (*Config, error) {
},
CSDefDuration: 300000000000,
}
err := sb_util.LoadConfig(path, &cfg, nil, nil, nil)
err := config_hdl.Load(&cfg, nil, nil, nil, path)
return &cfg, err
}
7 changes: 4 additions & 3 deletions util/logger.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,15 @@
package util

import (
sb_util "github.com/SENERGY-Platform/go-service-base/util"
sb_logger "github.com/SENERGY-Platform/go-service-base/logger"
"github.com/y-du/go-log-level"
"os"
)

var Logger *log_level.Logger

func InitLogger(config sb_util.LoggerConfig) (out *os.File, err error) {
Logger, out, err = sb_util.NewLogger(config)
func InitLogger(c LoggerConfig) (out *os.File, err error) {
Logger, out, err = sb_logger.New(c.Level, c.Path, c.FileName, c.Prefix, c.Utc, c.Terminal, c.Microseconds)
Logger.SetLevelPrefix("ERROR ", "WARNING ", "INFO ", "DEBUG ")
return
}

0 comments on commit 861b742

Please sign in to comment.