From f39533f6820c3ec014af409982ee3307ab8da9fb Mon Sep 17 00:00:00 2001 From: Shion Ichikawa Date: Sat, 12 Oct 2024 01:22:31 +0900 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20pkg/config?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pkg/config/.gitignore | 2 ++ pkg/config/config.go | 27 +++++++++++++++++++++++++++ pkg/config/line.go | 7 +++++++ pkg/config/setting.example.yaml | 7 +++++++ pkg/config/vonage.go | 6 ++++++ 5 files changed, 49 insertions(+) create mode 100644 pkg/config/.gitignore create mode 100644 pkg/config/config.go create mode 100644 pkg/config/line.go create mode 100644 pkg/config/setting.example.yaml create mode 100644 pkg/config/vonage.go diff --git a/pkg/config/.gitignore b/pkg/config/.gitignore new file mode 100644 index 0000000..5937e60 --- /dev/null +++ b/pkg/config/.gitignore @@ -0,0 +1,2 @@ +setting.*.yaml +!setting.example.yaml diff --git a/pkg/config/config.go b/pkg/config/config.go new file mode 100644 index 0000000..9a05f93 --- /dev/null +++ b/pkg/config/config.go @@ -0,0 +1,27 @@ +package config + +import ( + "gopkg.in/yaml.v3" + "log/slog" + "os" +) + +var Config config + +type config struct { + LineConfig LineConfig `yaml:"line"` + VonageConfig VonageConfig `yaml:"vonage"` +} + +func init() { + Config = config{} + loc := os.Getenv("ENV_LOCATION") + if loc == "" { + slog.Error("No ENV_LOCATION found") + return + } + if err := yaml.Unmarshal([]byte(loc), &Config); err != nil { + slog.Error("Failed to unmarshal yaml", err) + return + } +} diff --git a/pkg/config/line.go b/pkg/config/line.go new file mode 100644 index 0000000..226dc7d --- /dev/null +++ b/pkg/config/line.go @@ -0,0 +1,7 @@ +package config + +type LineConfig struct { + ClientID string `yaml:"channel_id"` + ChannelSecret string `yaml:"channel_secret"` + ChannelToken string `yaml:"channel_access_token"` +} diff --git a/pkg/config/setting.example.yaml b/pkg/config/setting.example.yaml new file mode 100644 index 0000000..269da9f --- /dev/null +++ b/pkg/config/setting.example.yaml @@ -0,0 +1,7 @@ +line: + channel_id: + channel_secret: + channel_access_token: +vonage: + x_vgai_key: + agent_id: diff --git a/pkg/config/vonage.go b/pkg/config/vonage.go new file mode 100644 index 0000000..7df0275 --- /dev/null +++ b/pkg/config/vonage.go @@ -0,0 +1,6 @@ +package config + +type VonageConfig struct { + VgaiKey string `yaml:"x_vgai_key"` + AgentID string `yaml:"agent_id"` +}