Get rid of flagger.

master
Stanislav Nikitin 1 month ago
parent dcd361de1f
commit 30f8b4975c
Signed by: pztrn
GPG Key ID: 1E944A0F0568B550
  1. 3
      cmd/fastpastebin/fastpastebin.go
  2. 1
      go.mod
  3. 3
      go.sum
  4. 34
      internal/context/context.go

@ -25,6 +25,7 @@
package main
import (
"flag"
"os"
"os/signal"
"syscall"
@ -48,7 +49,7 @@ func main() {
// to be added.
// Parse flags.
appCtx.Flagger.Parse()
flag.Parse()
// Continue loading.
appCtx.LoadConfiguration()

@ -15,7 +15,6 @@ require (
github.com/lib/pq v1.10.6
github.com/pressly/goose v2.7.0+incompatible
github.com/rs/zerolog v1.27.0
go.dev.pztrn.name/flagger v0.0.0-20211119225333-c010875aa337
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d
golang.org/x/net v0.0.0-20220624214902-1bab6f366d9e // indirect
golang.org/x/sys v0.0.0-20220624220833-87e55d714810 // indirect

@ -53,15 +53,12 @@ github.com/rs/xid v1.3.0/go.mod h1:trrq9SKmegXys3aeAKXMUTdJsYXVwGY3RLcfgqegfbg=
github.com/rs/zerolog v1.27.0 h1:1T7qCieN22GVc8S4Q2yuexzBb1EqjbgjSH9RohbMjKs=
github.com/rs/zerolog v1.27.0/go.mod h1:7frBqO0oezxmnO7GF86FY++uy8I0Tk/If5ni1G9Qc0U=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
github.com/valyala/fasttemplate v1.2.1 h1:TVEnxayobAdVkhQfrfes2IzOB6o+z4roRkPF52WA1u4=
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
go.dev.pztrn.name/flagger v0.0.0-20211119225333-c010875aa337 h1:OerezdlV+T80z1tCzOQg6HSpjheU3dmxHbUbQ8NVSAs=
go.dev.pztrn.name/flagger v0.0.0-20211119225333-c010875aa337/go.mod h1:ttPExQNCubgqqO5Y19LfIBKqmWtBocY7P9MXQEECuZo=
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d h1:sK3txAijHtOK88l68nt020reeT1ZdKLIYetKl95FzVY=
golang.org/x/crypto v0.0.0-20220622213112-05595931fe9d/go.mod h1:IxCIyHEi3zRg3s0A5j5BB6A9Jmi73HwBIUl50j+osU4=
golang.org/x/net v0.0.0-20211112202133-69e39bad7dc2/go.mod h1:9nx3DQGgdP8bBQD5qxJ1jj9UTztislL4KSBs9R2vV5Y=

@ -25,6 +25,7 @@
package context
import (
"flag"
"os"
"path/filepath"
@ -32,7 +33,6 @@ import (
"github.com/rs/zerolog"
"go.dev.pztrn.name/fastpastebin/internal/config"
databaseinterface "go.dev.pztrn.name/fastpastebin/internal/database/interface"
"go.dev.pztrn.name/flagger"
"gopkg.in/yaml.v2"
)
@ -41,26 +41,18 @@ import (
// contains everything every part of application need, like configuration
// access, logger, etc.
type Context struct {
Config *config.Struct
Database databaseinterface.Interface
Echo *echo.Echo
Flagger *flagger.Flagger
Logger zerolog.Logger
Config *config.Struct
Database databaseinterface.Interface
Echo *echo.Echo
Logger zerolog.Logger
configPathFromCLI string
}
// Initialize initializes context.
func (c *Context) Initialize() {
c.initializeLogger()
c.Flagger = flagger.New("fastpastebin", nil)
c.Flagger.Initialize()
_ = c.Flagger.AddFlag(&flagger.Flag{
Name: "config",
Description: "Configuration file path. Can be overridded with FASTPASTEBIN_CONFIG environment variable (this is what used in tests).",
Type: "string",
DefaultValue: "NO_CONFIG",
})
flag.StringVar(&c.configPathFromCLI, "config", "NO_CONFIG", "Configuration file path. Can be overridded with FASTPASTEBIN_CONFIG environment variable.")
}
// InitializePost initializes everything that needs a configuration.
@ -75,20 +67,18 @@ func (c *Context) InitializePost() {
func (c *Context) LoadConfiguration() {
c.Logger.Info().Msg("Loading configuration...")
configPath := ""
configPath := c.configPathFromCLI
// We're accepting configuration path from "-config" CLI parameter
// and FASTPASTEBIN_CONFIG environment variable. Later have higher
// weight and can override "-config" value.
configPathFromCLI, err := c.Flagger.GetStringValue("config")
configPathFromEnv, configPathFromEnvFound := os.LookupEnv("FASTPASTEBIN_CONFIG")
if err != nil && configPathFromEnvFound || err == nil && configPathFromEnvFound {
if configPathFromEnvFound {
configPath = configPathFromEnv
} else if err != nil && !configPathFromEnvFound || err == nil && configPathFromCLI == "NO_CONFIG" {
}
if configPath == "NO_CONFIG" {
c.Logger.Panic().Msg("Configuration file path wasn't passed via '-config' or 'FASTPASTEBIN_CONFIG' environment variable. Cannot continue.")
} else if err == nil && !configPathFromEnvFound {
configPath = configPathFromCLI
}
// Normalize file path.

Loading…
Cancel
Save