Skip to content

Commit

Permalink
refactor: remove koanf dependency
Browse files Browse the repository at this point in the history
  • Loading branch information
l3uddz committed Jul 1, 2020
1 parent 3cc3f4a commit e2e25b3
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 87 deletions.
30 changes: 13 additions & 17 deletions config/config.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package config

import (
"github.com/knadh/koanf"
"github.com/knadh/koanf/parsers/yaml"
"github.com/knadh/koanf/providers/file"
"fmt"
"github.com/l3uddz/crop/logger"
"github.com/l3uddz/crop/stringutils"
"gopkg.in/yaml.v2"
"io/ioutil"
)

type Configuration struct {
Expand All @@ -17,16 +17,11 @@ type Configuration struct {
/* Vars */

var (
cfgPath = ""

// Config exports the config object
Config *Configuration

// Internal
delimiter = "."
k = koanf.New(delimiter)

log = logger.GetLogger("cfg")
// internal
cfgPath = ""
log = logger.GetLogger("cfg")
)

/* Public */
Expand All @@ -35,14 +30,15 @@ func Init(configFilePath string) error {
// set package variables
cfgPath = configFilePath

// load config file
if err := k.Load(file.Provider(configFilePath), yaml.Parser()); err != nil {
return err
// read config file
b, err := ioutil.ReadFile(configFilePath)
if err != nil {
return fmt.Errorf("failed reading config file: %w", err)
}

// unmarshal into struct
if err := k.Unmarshal("", &Config); err != nil {
return err
// decode config file
if err := yaml.Unmarshal(b, &Config); err != nil {
return fmt.Errorf("failed decoding config file: %w", err)
}

return nil
Expand Down
16 changes: 8 additions & 8 deletions config/rclone.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package config

type RcloneConfig struct {
Path string `koanf:"path"`
Config string `koanf:"config"`
Stats string `koanf:"stats"`
LiveRotate bool `koanf:"live_rotate"`
DryRun bool `koanf:"dry_run"`
ServiceAccountRemotes map[string][]string `koanf:"service_account_remotes"`
GlobalParams map[string]RcloneParams `koanf:"global_params"`
Path string `yaml:"path"`
Config string `yaml:"config"`
Stats string `yaml:"stats"`
LiveRotate bool `yaml:"live_rotate"`
DryRun bool `yaml:"dry_run"`
ServiceAccountRemotes map[string][]string `yaml:"service_account_remotes"`
GlobalParams map[string]RcloneParams `yaml:"global_params"`
}

type RcloneServerSide struct {
Expand All @@ -18,7 +18,7 @@ type RcloneServerSide struct {
type RcloneParams struct {
Copy []string
Move []string
MoveServerSide []string `koanf:"move_server_side"`
MoveServerSide []string `yaml:"move_server_side"`
Sync []string
Dedupe []string
}
16 changes: 8 additions & 8 deletions config/syncer.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,25 +3,25 @@ package config
type SyncerRemotes struct {
Copy []string
Sync []string
MoveServerSide []RcloneServerSide `koanf:"move_server_side"`
MoveServerSide []RcloneServerSide `yaml:"move_server_side"`
Dedupe []string
}

type SyncerRcloneParams struct {
Copy []string
GlobalCopy string `koanf:"global_copy"`
GlobalCopy string `yaml:"global_copy"`
Sync []string
GlobalSync string `koanf:"global_sync"`
MoveServerSide []string `koanf:"move_server_side"`
GlobalMoveServerSide string `koanf:"global_move_server_side"`
GlobalSync string `yaml:"global_sync"`
MoveServerSide []string `yaml:"move_server_side"`
GlobalMoveServerSide string `yaml:"global_move_server_side"`
Dedupe []string
GlobalDedupe string `koanf:"global_dedupe"`
GlobalDedupe string `yaml:"global_dedupe"`
}

type SyncerConfig struct {
Name string
Enabled bool
SourceRemote string `koanf:"source_remote"`
SourceRemote string `yaml:"source_remote"`
Remotes SyncerRemotes
RcloneParams SyncerRcloneParams `koanf:"rclone_params"`
RcloneParams SyncerRcloneParams `yaml:"rclone_params"`
}
16 changes: 8 additions & 8 deletions config/uploader.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,27 +20,27 @@ type UploaderRemotes struct {
Clean []string
Copy []string
Move string
MoveServerSide []RcloneServerSide `koanf:"move_server_side"`
MoveServerSide []RcloneServerSide `yaml:"move_server_side"`
Dedupe []string
}

type UploaderRcloneParams struct {
Copy []string
GlobalCopy string `koanf:"global_copy"`
GlobalCopy string `yaml:"global_copy"`
Move []string
GlobalMove string `koanf:"global_move"`
MoveServerSide []string `koanf:"move_server_side"`
GlobalMoveServerSide string `koanf:"global_move_server_side"`
GlobalMove string `yaml:"global_move"`
MoveServerSide []string `yaml:"move_server_side"`
GlobalMoveServerSide string `yaml:"global_move_server_side"`
Dedupe []string
GlobalDedupe string `koanf:"global_dedupe"`
GlobalDedupe string `yaml:"global_dedupe"`
}

type UploaderConfig struct {
Name string
Enabled bool
Check UploaderCheck
Hidden UploaderHidden
LocalFolder string `koanf:"local_folder"`
LocalFolder string `yaml:"local_folder"`
Remotes UploaderRemotes
RcloneParams UploaderRcloneParams `koanf:"rclone_params"`
RcloneParams UploaderRcloneParams `yaml:"rclone_params"`
}
20 changes: 9 additions & 11 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,35 +8,33 @@ require (
github.com/blang/semver v3.5.1+incompatible
github.com/dgraph-io/badger/v2 v2.0.3 // indirect
github.com/dustin/go-humanize v1.0.0
github.com/fsnotify/fsnotify v1.4.9 // indirect
github.com/go-cmd/cmd v1.2.0
github.com/gofiber/fiber v1.11.1
github.com/gofiber/recover v0.1.0
github.com/gofiber/fiber v1.12.2
github.com/gofiber/recover v0.1.1
github.com/golang/protobuf v1.4.2 // indirect
github.com/klauspost/compress v1.10.8 // indirect
github.com/knadh/koanf v0.10.0
github.com/mattn/go-colorable v0.1.6 // indirect
github.com/klauspost/compress v1.10.10 // indirect
github.com/mgutz/ansi v0.0.0-20170206155736-9520e82c474b // indirect
github.com/mitchellh/mapstructure v1.3.2 // indirect
github.com/natefinch/lumberjack v2.0.0+incompatible
github.com/nightlyone/lockfile v1.0.0
github.com/onsi/ginkgo v1.12.0 // indirect
github.com/onsi/gomega v1.9.0 // indirect
github.com/pelletier/go-toml v1.8.0 // indirect
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2
github.com/pkg/errors v0.9.1
github.com/rhysd/go-github-selfupdate v1.2.2
github.com/sirupsen/logrus v1.6.0
github.com/sony/sonyflake v1.0.0 // indirect
github.com/spf13/cobra v1.0.0
github.com/spf13/pflag v1.0.5 // indirect
github.com/ulikunitz/xz v0.5.7 // indirect
github.com/x-cray/logrus-prefixed-formatter v0.5.2
github.com/yale8848/gorpool v0.1.0
github.com/zippoxer/bow v0.0.0-20200229231453-bf1012ae7ab9
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9 // indirect
golang.org/x/net v0.0.0-20200602114024-627f9648deb9 // indirect
golang.org/x/net v0.0.0-20200625001655-4c5254603344 // indirect
golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d // indirect
golang.org/x/sys v0.0.0-20200615200032-f1bc736245b1
golang.org/x/sys v0.0.0-20200625212154-ddb9806d33ae
google.golang.org/appengine v1.6.6 // indirect
google.golang.org/protobuf v1.24.0 // indirect
google.golang.org/protobuf v1.25.0 // indirect
gopkg.in/natefinch/lumberjack.v2 v2.0.0 // indirect
gopkg.in/yaml.v2 v2.3.0
)
Loading

0 comments on commit e2e25b3

Please sign in to comment.