From 8fa064bc03e46705153ea7377c94c40b6ccae517 Mon Sep 17 00:00:00 2001 From: alexadhy Date: Thu, 11 Feb 2021 01:28:50 +0700 Subject: [PATCH 1/2] leverage go1.16 to embed reference config --- config.reference.json | 34 +------------ config/config.go | 66 +++++++++++++------------- dep/orchestrator/config.reference.json | 33 +++++++++++++ dep/orchestrator/orchestrate.go | 8 +++- go.mod | 2 +- go.sum | 1 - 6 files changed, 74 insertions(+), 70 deletions(-) mode change 100644 => 120000 config.reference.json create mode 100644 dep/orchestrator/config.reference.json diff --git a/config.reference.json b/config.reference.json deleted file mode 100644 index 976f2a7..0000000 --- a/config.reference.json +++ /dev/null @@ -1,33 +0,0 @@ -{ - "dev": true, - "binaries": [ - { - "name": "grafana", - "version": "7.4.0" - }, - { - "name": "goreleaser", - "version": "0.155.1" - }, - { - "name": "caddy", - "version": "2.3.0" - }, - { - "name": "protoc", - "version": "3.14.0" - }, - { - "name": "protoc-gen-go", - "version": "1.25.0" - }, - { - "name": "protoc-gen-cobra", - "version": "0.4.1" - }, - { - "name": "protoc-gen-go-grpc", - "version": "1.1.0" - } - ] -} \ No newline at end of file diff --git a/config.reference.json b/config.reference.json new file mode 120000 index 0000000..e04358a --- /dev/null +++ b/config.reference.json @@ -0,0 +1 @@ +dep/orchestrator/config.reference.json \ No newline at end of file diff --git a/config/config.go b/config/config.go index 613a38a..fa7d3ea 100644 --- a/config/config.go +++ b/config/config.go @@ -35,36 +35,36 @@ func (ac *AppConfig) GetVersion(pkgName string) string { return "" } -var DefaultConfig = AppConfig{ - DevMode: true, - Binaries: []BinaryInfo{ - { - Name: "grafana", - Version: "7.4.0", - }, - { - Name: "goreleaser", - Version: "0.155.1", - }, - { - Name: "caddy", - Version: "2.3.0", - }, - { - Name: "protoc", - Version: "3.14.0", - }, - { - Name: "protoc-gen-go", - Version: "1.25.0", - }, - { - Name: "protoc-gen-cobra", - Version: "0.4.1", - }, - { - Name: "protoc-gen-go-grpc", - Version: "1.1.0", - }, - }, -} +// var DefaultConfig = AppConfig{ +// DevMode: true, +// Binaries: []BinaryInfo{ +// { +// Name: "grafana", +// Version: "7.4.0", +// }, +// { +// Name: "goreleaser", +// Version: "0.155.1", +// }, +// { +// Name: "caddy", +// Version: "2.3.0", +// }, +// { +// Name: "protoc", +// Version: "3.14.0", +// }, +// { +// Name: "protoc-gen-go", +// Version: "1.25.0", +// }, +// { +// Name: "protoc-gen-cobra", +// Version: "0.4.1", +// }, +// { +// Name: "protoc-gen-go-grpc", +// Version: "1.1.0", +// }, +// }, +// } diff --git a/dep/orchestrator/config.reference.json b/dep/orchestrator/config.reference.json new file mode 100644 index 0000000..976f2a7 --- /dev/null +++ b/dep/orchestrator/config.reference.json @@ -0,0 +1,33 @@ +{ + "dev": true, + "binaries": [ + { + "name": "grafana", + "version": "7.4.0" + }, + { + "name": "goreleaser", + "version": "0.155.1" + }, + { + "name": "caddy", + "version": "2.3.0" + }, + { + "name": "protoc", + "version": "3.14.0" + }, + { + "name": "protoc-gen-go", + "version": "1.25.0" + }, + { + "name": "protoc-gen-cobra", + "version": "0.4.1" + }, + { + "name": "protoc-gen-go-grpc", + "version": "1.1.0" + } + ] +} \ No newline at end of file diff --git a/dep/orchestrator/orchestrate.go b/dep/orchestrator/orchestrate.go index 57c0446..10a5bf6 100644 --- a/dep/orchestrator/orchestrate.go +++ b/dep/orchestrator/orchestrate.go @@ -1,7 +1,7 @@ package orchestrator import ( - "encoding/json" + "embed" "github.com/spf13/cobra" "io/ioutil" "path/filepath" @@ -16,6 +16,10 @@ import ( "go.amplifyedge.org/booty-v2/internal/store" ) +//go:embed config.reference.json + +var staticConfig embed.FS + // Orchestrator implements Agent type Orchestrator struct { cfg *config.AppConfig @@ -40,7 +44,7 @@ func NewOrchestrator(app string) *Orchestrator { fileContent, err := ioutil.ReadFile(configPath) if err != nil { // use default config - fileContent, err = json.Marshal(&config.DefaultConfig) + fileContent, err = staticConfig.ReadFile("config.reference.json") if err != nil { logger.Fatalf("error encoding default json config") } diff --git a/go.mod b/go.mod index b676eb4..b360408 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module go.amplifyedge.org/booty-v2 -go 1.15 +go 1.16 require ( github.com/cheggaaa/pb v1.0.27 diff --git a/go.sum b/go.sum index 00711c4..6883714 100644 --- a/go.sum +++ b/go.sum @@ -187,7 +187,6 @@ github.com/oklog/ulid v1.3.1/go.mod h1:CirwcVhetQ6Lv90oh/F+FBtV6XMibvdAFo93nm5qn github.com/otiai10/copy v1.4.2 h1:RTiz2sol3eoXPLF4o+YWqEybwfUa/Q2Nkc4ZIUs3fwI= github.com/otiai10/copy v1.4.2/go.mod h1:XWfuS3CrI0R6IE0FbgHsEazaXO8G0LpMp9o8tos0x4E= github.com/otiai10/curr v0.0.0-20150429015615-9b4961190c95/go.mod h1:9qAhocn7zKJG+0mI8eUu6xqkFDYS2kb2saOteoSB3cE= -github.com/otiai10/curr v1.0.0 h1:TJIWdbX0B+kpNagQrjgq8bCMrbhiuX73M2XwgtDMoOI= github.com/otiai10/curr v1.0.0/go.mod h1:LskTG5wDwr8Rs+nNQ+1LlxRjAtTZZjtJW4rMXl6j4vs= github.com/otiai10/mint v1.3.0/go.mod h1:F5AjcsTsWUqX+Na9fpHb52P8pcRX2CI6A3ctIT91xUo= github.com/otiai10/mint v1.3.2 h1:VYWnrP5fXmz1MXvjuUvcBrXSjGE6xjON+axB/UrpO3E= From 22055ae20318ffb8a30981d756fc74abebbcb984 Mon Sep 17 00:00:00 2001 From: alexadhy Date: Thu, 11 Feb 2021 01:37:39 +0700 Subject: [PATCH 2/2] moved reference config to config dir --- config.reference.json | 2 +- config/config.go | 39 +++---------------- .../config.reference.json | 0 dep/orchestrator/orchestrate.go | 7 +--- 4 files changed, 7 insertions(+), 41 deletions(-) rename {dep/orchestrator => config}/config.reference.json (100%) diff --git a/config.reference.json b/config.reference.json index e04358a..1baa531 120000 --- a/config.reference.json +++ b/config.reference.json @@ -1 +1 @@ -dep/orchestrator/config.reference.json \ No newline at end of file +config/config.reference.json \ No newline at end of file diff --git a/config/config.go b/config/config.go index fa7d3ea..9dc00fb 100644 --- a/config/config.go +++ b/config/config.go @@ -3,11 +3,16 @@ package config import ( + "embed" "encoding/json" "go.amplifyedge.org/booty-v2/internal/logging" ) +//go:embed config.reference.json + +var DefaultConfig embed.FS + type BinaryInfo struct { Name string `json:"name"` Version string `json:"version"` @@ -34,37 +39,3 @@ func (ac *AppConfig) GetVersion(pkgName string) string { } return "" } - -// var DefaultConfig = AppConfig{ -// DevMode: true, -// Binaries: []BinaryInfo{ -// { -// Name: "grafana", -// Version: "7.4.0", -// }, -// { -// Name: "goreleaser", -// Version: "0.155.1", -// }, -// { -// Name: "caddy", -// Version: "2.3.0", -// }, -// { -// Name: "protoc", -// Version: "3.14.0", -// }, -// { -// Name: "protoc-gen-go", -// Version: "1.25.0", -// }, -// { -// Name: "protoc-gen-cobra", -// Version: "0.4.1", -// }, -// { -// Name: "protoc-gen-go-grpc", -// Version: "1.1.0", -// }, -// }, -// } diff --git a/dep/orchestrator/config.reference.json b/config/config.reference.json similarity index 100% rename from dep/orchestrator/config.reference.json rename to config/config.reference.json diff --git a/dep/orchestrator/orchestrate.go b/dep/orchestrator/orchestrate.go index 10a5bf6..1e2bab8 100644 --- a/dep/orchestrator/orchestrate.go +++ b/dep/orchestrator/orchestrate.go @@ -1,7 +1,6 @@ package orchestrator import ( - "embed" "github.com/spf13/cobra" "io/ioutil" "path/filepath" @@ -16,10 +15,6 @@ import ( "go.amplifyedge.org/booty-v2/internal/store" ) -//go:embed config.reference.json - -var staticConfig embed.FS - // Orchestrator implements Agent type Orchestrator struct { cfg *config.AppConfig @@ -44,7 +39,7 @@ func NewOrchestrator(app string) *Orchestrator { fileContent, err := ioutil.ReadFile(configPath) if err != nil { // use default config - fileContent, err = staticConfig.ReadFile("config.reference.json") + fileContent, err = config.DefaultConfig.ReadFile("config.reference.json") if err != nil { logger.Fatalf("error encoding default json config") }