diff --git a/amazon_transcribe_handler.go b/amazon_transcribe_handler.go index a2cbbce..2c9b27e 100644 --- a/amazon_transcribe_handler.go +++ b/amazon_transcribe_handler.go @@ -12,7 +12,7 @@ import ( ) func init() { - ServiceHandlers.Register("aws", new(AmazonTranscribeHandler)) + ServiceHandlerMakers.Register("aws", new(AmazonTranscribeHandlerMaker)) } type AmazonTranscribeHandler struct { @@ -29,7 +29,9 @@ type AmazonTranscribeHandler struct { OnResultFunc func(context.Context, io.WriteCloser, string, string, string, any) error } -func (h *AmazonTranscribeHandler) New(config Config, channelID, connectionID string, sampleRate uint32, channelCount uint16, languageCode string, onResultFunc any) serviceHandlerInterface { +type AmazonTranscribeHandlerMaker struct{} + +func (h *AmazonTranscribeHandlerMaker) New(config Config, channelID, connectionID string, sampleRate uint32, channelCount uint16, languageCode string, onResultFunc any) serviceHandlerInterface { return &AmazonTranscribeHandler{ Config: config, ChannelID: channelID, diff --git a/cmd/suzu/main.go b/cmd/suzu/main.go index 041e14d..3263d73 100644 --- a/cmd/suzu/main.go +++ b/cmd/suzu/main.go @@ -17,7 +17,7 @@ func main() { // bin/suzu -C config.ini configFilePath := flag.String("C", "./config.ini", "設定ファイルへのパス") - serviceType := flag.String("service", "aws", fmt.Sprintf("音声文字変換のサービス(%s)", strings.Join(suzu.ServiceHandlers.GetNames([]string{"test", "dump"}), ", "))) + serviceType := flag.String("service", "aws", fmt.Sprintf("音声文字変換のサービス(%s)", strings.Join(suzu.ServiceHandlerMakers.GetNames([]string{"test", "dump"}), ", "))) flag.Parse() if *showVersion { diff --git a/handler.go b/handler.go index 87a8643..8f10cdb 100644 --- a/handler.go +++ b/handler.go @@ -38,7 +38,7 @@ func NewSuzuErrorResponse(err error) TranscriptionResult { } func getServiceHandler(serviceType string, config Config, channelID, connectionID string, sampleRate uint32, channelCount uint16, languageCode string, onResultFunc any) (serviceHandlerInterface, error) { - handler, err := ServiceHandlers.Get(serviceType) + handler, err := ServiceHandlerMakers.Get(serviceType) if err != nil { return nil, err } diff --git a/packet_dump_handler.go b/packet_dump_handler.go index 11e44d7..dfa315f 100644 --- a/packet_dump_handler.go +++ b/packet_dump_handler.go @@ -10,7 +10,7 @@ import ( ) func init() { - ServiceHandlers.Register("dump", new(PacketDumpHandler)) + ServiceHandlerMakers.Register("dump", new(PacketDumpHandlerMaker)) } type PacketDumpHandler struct { @@ -27,7 +27,9 @@ type PacketDumpHandler struct { OnResultFunc func(context.Context, io.WriteCloser, string, string, string, any) error } -func (h *PacketDumpHandler) New(config Config, channelID, connectionID string, sampleRate uint32, channelCount uint16, languageCode string, onResultFunc any) serviceHandlerInterface { +type PacketDumpHandlerMaker struct{} + +func (h *PacketDumpHandlerMaker) New(config Config, channelID, connectionID string, sampleRate uint32, channelCount uint16, languageCode string, onResultFunc any) serviceHandlerInterface { return &PacketDumpHandler{ Config: config, ChannelID: channelID, diff --git a/service_handler.go b/service_handler.go index 9419ba6..1c198b6 100644 --- a/service_handler.go +++ b/service_handler.go @@ -9,45 +9,48 @@ import ( ) var ( - ServiceHandlers = NewServiceHandlers() + ServiceHandlerMakers = NewServiceHandlerMakers() ErrServiceNotFound = fmt.Errorf("SERVICE-NOT-FOUND") ) +type serviceHandlerMakerInterface interface { + New(Config, string, string, uint32, uint16, string, any) serviceHandlerInterface +} + type serviceHandlerInterface interface { Handle(context.Context, io.Reader) (*io.PipeReader, error) UpdateRetryCount() int GetRetryCount() int ResetRetryCount() int - New(Config, string, string, uint32, uint16, string, any) serviceHandlerInterface } -type serviceHandlers struct { - Handlers map[string]serviceHandlerInterface +type serviceHandlerMakers struct { + Makers map[string]serviceHandlerMakerInterface } -func NewServiceHandlers() serviceHandlers { - return serviceHandlers{ - Handlers: make(map[string]serviceHandlerInterface), +func NewServiceHandlerMakers() serviceHandlerMakers { + return serviceHandlerMakers{ + Makers: make(map[string]serviceHandlerMakerInterface), } } -func (h *serviceHandlers) Register(name string, f serviceHandlerInterface) { - h.Handlers[name] = f +func (h *serviceHandlerMakers) Register(name string, f serviceHandlerMakerInterface) { + h.Makers[name] = f } -func (h *serviceHandlers) Get(name string) (serviceHandlerInterface, error) { - handler, ok := h.Handlers[name] +func (h *serviceHandlerMakers) Get(name string) (serviceHandlerMakerInterface, error) { + maker, ok := h.Makers[name] if !ok { return nil, ErrServiceNotFound } - return handler, nil + return maker, nil } -func (h *serviceHandlers) GetNames(exclude []string) []string { - handlers := h.Handlers - names := make([]string, 0, len(handlers)) - for name := range handlers { +func (h *serviceHandlerMakers) GetNames(exclude []string) []string { + makers := h.Makers + names := make([]string, 0, len(makers)) + for name := range makers { if slices.Contains(exclude, name) { continue } diff --git a/speech_to_text_handler.go b/speech_to_text_handler.go index b120d21..52d62a9 100644 --- a/speech_to_text_handler.go +++ b/speech_to_text_handler.go @@ -15,7 +15,7 @@ import ( ) func init() { - ServiceHandlers.Register("gcp", new(SpeechToTextHandler)) + ServiceHandlerMakers.Register("gcp", new(SpeechToTextHandlerMaker)) } type SpeechToTextHandler struct { @@ -32,7 +32,9 @@ type SpeechToTextHandler struct { OnResultFunc func(context.Context, io.WriteCloser, string, string, string, any) error } -func (h *SpeechToTextHandler) New(config Config, channelID, connectionID string, sampleRate uint32, channelCount uint16, languageCode string, onResultFunc any) serviceHandlerInterface { +type SpeechToTextHandlerMaker struct{} + +func (h *SpeechToTextHandlerMaker) New(config Config, channelID, connectionID string, sampleRate uint32, channelCount uint16, languageCode string, onResultFunc any) serviceHandlerInterface { return &SpeechToTextHandler{ Config: config, ChannelID: channelID, diff --git a/test_handler.go b/test_handler.go index f02c148..7807665 100644 --- a/test_handler.go +++ b/test_handler.go @@ -11,7 +11,7 @@ import ( ) func init() { - ServiceHandlers.Register("test", new(TestHandler)) + ServiceHandlerMakers.Register("test", new(TestHandlerMaker)) } type TestHandler struct { @@ -28,7 +28,9 @@ type TestHandler struct { OnResultFunc func(context.Context, io.WriteCloser, string, string, string, any) error } -func (h *TestHandler) New(config Config, channelID, connectionID string, sampleRate uint32, channelCount uint16, languageCode string, onResultFunc any) serviceHandlerInterface { +type TestHandlerMaker struct{} + +func (h *TestHandlerMaker) New(config Config, channelID, connectionID string, sampleRate uint32, channelCount uint16, languageCode string, onResultFunc any) serviceHandlerInterface { return &TestHandler{ Config: config, ChannelID: channelID,