Skip to content

gRPCのサーバを接続 / 設定情報をenumで定義 #45

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Sep 10, 2023
Prev Previous commit
Next Next commit
feat: AIのリソースを切り替えられるように変更
*今はgRPCのサーバのみ実装
  • Loading branch information
mochi-yu committed Sep 10, 2023
commit d6ef59d26e9091c98e2628019f19c572415457dd
24 changes: 14 additions & 10 deletions cmd/suggest.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"strings"

tea "github.com/charmbracelet/bubbletea"
"github.com/cocoide/commitify/internal/entity"
"github.com/cocoide/commitify/internal/gateway"
"github.com/cocoide/commitify/util"
"github.com/fatih/color"
Expand All @@ -21,17 +22,20 @@ type model struct {
}

func (m *model) Init() tea.Cmd {
// 本当はこう書きたい。今は一旦全てgrpcサーバに呼び出し
// switch conf.endpoint {
// case openai:
// ~~~
// case grpc_serve:
// ~~~
// }
// var gateway gatewayInterface
conf, err := entity.ReadConfig()
if err != nil {
log.Fatal("設定情報の取得に失敗: ", err)
}

var gi gateway.GatewayInterface
switch conf.AISource {
case int(entity.WrapServer):
gi = gateway.NewGrpcServeGateway()
default:
gi = gateway.NewGrpcServeGateway()
}

gsg := gateway.NewGrpcServeGateway()
messages, err := gsg.FetchCommitMessages()
messages, err := gi.FetchCommitMessages()
if err != nil {
log.Fatal("コミットメッセージの生成に失敗: ", err)
os.Exit(-1)
Expand Down
5 changes: 5 additions & 0 deletions internal/gateway/gateway_interface.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package gateway

type GatewayInterface interface {
FetchCommitMessages() ([]string, error)
}