Skip to content

Commit

Permalink
./bin/suzu -V と VERSION ファイルを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
voluntas committed Sep 8, 2023
1 parent 460eaa7 commit c18bff6
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 13 deletions.
1 change: 1 addition & 0 deletions VERSION
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
2023.4.0
20 changes: 10 additions & 10 deletions cmd/suzu/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 7 additions & 1 deletion config.go
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
package suzu

import (
_ "embed"
"fmt"
"net/netip"

zlog "github.com/rs/zerolog/log"
"gopkg.in/ini.v1"
)

//go:embed VERSION
var Version string

const (
DefaultLogDir = "."
DefaultLogName = "suzu.jsonl"
Expand All @@ -26,7 +30,7 @@ const (
)

type Config struct {
Revision string
Version string

Debug bool `ini:"debug"`

Expand Down Expand Up @@ -122,6 +126,8 @@ func NewConfig(configFilePath string) (*Config, error) {
}

func setDefaultsConfig(config *Config) {
config.Version = Version

if config.LogDir == "" {
config.LogDir = DefaultLogDir
}
Expand Down
2 changes: 1 addition & 1 deletion healthcheck_handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
})
}
2 changes: 1 addition & 1 deletion healthcheck_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit c18bff6

Please sign in to comment.