From c18bff6e05499378a097cf0d7fed8566a2274592 Mon Sep 17 00:00:00 2001 From: voluntas Date: Fri, 8 Sep 2023 15:42:05 +0900 Subject: [PATCH] =?UTF-8?q?./bin/suzu=20-V=20=E3=81=A8=20VERSION=20?= =?UTF-8?q?=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- VERSION | 1 + cmd/suzu/main.go | 20 ++++++++++---------- config.go | 8 +++++++- healthcheck_handler.go | 2 +- healthcheck_handler_test.go | 2 +- 5 files changed, 20 insertions(+), 13 deletions(-) create mode 100644 VERSION diff --git a/VERSION b/VERSION new file mode 100644 index 0000000..b0db10d --- /dev/null +++ b/VERSION @@ -0,0 +1 @@ +2023.4.0 \ No newline at end of file diff --git a/cmd/suzu/main.go b/cmd/suzu/main.go index f14a647..0226bb1 100644 --- a/cmd/suzu/main.go +++ b/cmd/suzu/main.go @@ -11,26 +11,26 @@ import ( "golang.org/x/sync/errgroup" ) -var ( - // git rev-parse --short HEAD - revision string = "air" -) - func main() { - // XXX(v): とりあえず 同じ場所にある config.ini を読みに行く実装 - configFilePath := flag.String("C", "config.ini", "suzu の設定ファイルへのパス") + // /bin/kohaku -V + showVersion := flag.Bool("V", false, "バージョン") + + // bin/suzu -C config.ini + configFilePath := flag.String("C", "./config.ini", "設定ファイルへのパス") serviceType := flag.String("service", "aws", fmt.Sprintf("音声文字変換のサービス(%s)", strings.Join(suzu.NewServiceHandlerFuncs.GetNames([]string{"test", "dump"}), ", "))) flag.Parse() + if *showVersion { + fmt.Printf("Audio Streaming Gateway Suzu version %s\n", suzu.Version) + return + } + config, err := suzu.NewConfig(*configFilePath) if err != nil { // パースに失敗した場合 Fatal で終了 log.Fatal("cannot parse config file, err=", err) } - // リビジョンを追加 - config.Revision = revision - // ロガー初期化 err = suzu.InitLogger(config) if err != nil { diff --git a/config.go b/config.go index 8322dca..4fee353 100644 --- a/config.go +++ b/config.go @@ -1,6 +1,7 @@ package suzu import ( + _ "embed" "fmt" "net/netip" @@ -8,6 +9,9 @@ import ( "gopkg.in/ini.v1" ) +//go:embed VERSION +var Version string + const ( DefaultLogDir = "." DefaultLogName = "suzu.jsonl" @@ -26,7 +30,7 @@ const ( ) type Config struct { - Revision string + Version string Debug bool `ini:"debug"` @@ -122,6 +126,8 @@ func NewConfig(configFilePath string) (*Config, error) { } func setDefaultsConfig(config *Config) { + config.Version = Version + if config.LogDir == "" { config.LogDir = DefaultLogDir } diff --git a/healthcheck_handler.go b/healthcheck_handler.go index ca056c3..2e7c7a0 100644 --- a/healthcheck_handler.go +++ b/healthcheck_handler.go @@ -8,6 +8,6 @@ import ( func (s *Server) healthcheckHandler(c echo.Context) error { return c.JSON(http.StatusOK, map[string]interface{}{ - "revision": s.config.Revision, + "version": s.config.Version, }) } diff --git a/healthcheck_handler_test.go b/healthcheck_handler_test.go index 387c01c..7b370b2 100644 --- a/healthcheck_handler_test.go +++ b/healthcheck_handler_test.go @@ -36,7 +36,7 @@ func TestHealthcheckHandler(t *testing.T) { if err != nil { t.Fatal(err) } - body := fmt.Sprintf(`{"revision":"%s"}`, s.config.Revision) + body := fmt.Sprintf(`{"version":"%s"}`, s.config.Version) testCaces := []struct { Name string