Skip to content

Commit

Permalink
renames interface to Server
Browse files Browse the repository at this point in the history
  • Loading branch information
shubhang.balkundi committed Nov 26, 2020
1 parent d707992 commit fa38348
Show file tree
Hide file tree
Showing 8 changed files with 26 additions and 24 deletions.
5 changes: 3 additions & 2 deletions pkg/kstream/consumer_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ func (c consumerTestMockApp) MetricPublisher() z.MetricPublisher {
panic("implement me")
}

func (c consumerTestMockApp) HTTPServer() z.HttpServer {
func (c consumerTestMockApp) HTTPServer() z.Server {
panic("implement me")
}

Expand Down Expand Up @@ -64,7 +64,8 @@ func TestConsumer_create(t *testing.T) {
startConsumer = oldStartConsumer
createConsumer = oldCreateConsumer
}()
startConsumer = func(ctx context.Context, app z.App, h z.MessageHandler, consumer *kafka.Consumer, topicEntity string, instanceID string, wg *sync.WaitGroup) {}
startConsumer = func(ctx context.Context, app z.App, h z.MessageHandler, consumer *kafka.Consumer, topicEntity string, instanceID string, wg *sync.WaitGroup) {
}
createConsumer = func(consumerConfig *kafka.ConfigMap, topics []string) *kafka.Consumer {
return &kafka.Consumer{}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/kstream/kstreams_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (k kstreamMockApp) MetricPublisher() z.MetricPublisher {
panic("implement me")
}

func (k kstreamMockApp) HTTPServer() z.HttpServer {
func (k kstreamMockApp) HTTPServer() z.Server {
panic("implement me")
}

Expand Down
11 changes: 7 additions & 4 deletions pkg/mock/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ type App struct {
MessageRetryFunc func() z.MessageRetry
MessageHandlerFunc func() z.MessageHandler
MetricPublisherFunc func() z.MetricPublisher
HTTPServerFunc func() z.HttpServer
HTTPServerFunc func() z.Server
ConfigFunc func() *basic.Config
ConfigStoreFunc func() z.ConfigStore
}

func NewMockApp() *App {
func NewApp() *App {
return &App{
ContextFunc: func() context.Context {
return context.Background()
Expand All @@ -30,7 +30,7 @@ func NewMockApp() *App {
return z.ProcessingSuccess
})
},
HTTPServerFunc: func() z.HttpServer {
HTTPServerFunc: func() z.Server {
return nil
},
ConfigFunc: func() *basic.Config {
Expand All @@ -39,6 +39,9 @@ func NewMockApp() *App {
ConfigStoreFunc: func() z.ConfigStore {
return nil
},
MessageRetryFunc: func() z.MessageRetry {
return NewRetry()
},
}
}

Expand All @@ -62,7 +65,7 @@ func (m *App) MetricPublisher() z.MetricPublisher {
return m.MetricPublisher()
}

func (m *App) HTTPServer() z.HttpServer {
func (m *App) HTTPServer() z.Server {
return m.HTTPServerFunc()
}

Expand Down
2 changes: 1 addition & 1 deletion pkg/mock/metrics.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ type Metrics struct {
GaugeFunc func(metricName string, value int64, arguments map[string]string) error
}

func NewMockMetrics() *Metrics {
func NewMetrics() *Metrics {
return &Metrics{
StartFunc: func(a z.App) error {
return nil
Expand Down
8 changes: 4 additions & 4 deletions pkg/mock/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ type Retry struct {
StartFunc func(app z.App) error
RetryFunc func(app z.App, payload basic.MessageEvent) error
StopFunc func() error
ReplayFunc func() error
ReplayFunc func(app z.App, topicEntity string, count int) error
}

func NewMockRetry() *Retry {
func NewRetry() *Retry {
return &Retry{
StartFunc: func(app z.App) error {
return nil
Expand All @@ -23,7 +23,7 @@ func NewMockRetry() *Retry {
StopFunc: func() error {
return nil
},
ReplayFunc: func() error {
ReplayFunc: func(app z.App, topicEntity string, count int) error {
return nil
},
}
Expand All @@ -42,5 +42,5 @@ func (m *Retry) Stop() error {
}

func (m *Retry) Replay(app z.App, topicEntity string, count int) error {
return m.ReplayFunc()
return m.ReplayFunc(app, topicEntity, count)
}
2 changes: 1 addition & 1 deletion pkg/mw/middleware_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (m mwMockApp) MetricPublisher() z.MetricPublisher {
panic("implement me")
}

func (m mwMockApp) HTTPServer() z.HttpServer {
func (m mwMockApp) HTTPServer() z.Server {
panic("implement me")
}

Expand Down
14 changes: 6 additions & 8 deletions pkg/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,7 @@ type DefaultHttpServer struct {
router *httprouter.Router
}

type ReplayResponse struct {
Status bool `json:"status"`
Count int `json:"count"`
Msg string `json:"msg"`
}

func NewDefaultHTTPServer(config z.ConfigStore) z.HttpServer {
func NewDefaultHTTPServer(config z.ConfigStore) z.Server {
port := config.Config().HTTPServer.Port
if port == "" {
port = defaultHTTPPort
Expand All @@ -44,10 +38,14 @@ func (s *DefaultHttpServer) Start(app z.App) {
}(s.server)
}

func (s *DefaultHttpServer) ConfigureHTTPRoutes(a z.App, configFunc func(a z.App, h http.Handler)) {
func (s *DefaultHttpServer) ConfigureRoutes(a z.App, configFunc func(a z.App, h http.Handler)) {
configFunc(a, s.router)
}

func (s *DefaultHttpServer) Handler() http.Handler {
return s.router
}

func (s *DefaultHttpServer) Stop(app z.App) error {
return s.server.Shutdown(app.Context())
}
6 changes: 3 additions & 3 deletions pkg/zig/ziggurat.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import (
)

type Ziggurat struct {
httpServer ztype.HttpServer
httpServer ztype.Server
messageRetry ztype.MessageRetry
configStore ztype.ConfigStore
handler ztype.MessageHandler
Expand Down Expand Up @@ -127,7 +127,7 @@ func (z *Ziggurat) Run(handler ztype.MessageHandler, routes []string, opts ...zt
z.messageRetry = runOptions.Retry(z.configStore)
z.httpServer = runOptions.HTTPServer(z.configStore)
z.metricPublisher = runOptions.MetricPublisher(z.configStore)
z.httpServer.ConfigureHTTPRoutes(z, runOptions.HTTPConfigFunc)
z.httpServer.ConfigureRoutes(z, runOptions.HTTPConfigFunc)
z.stopFunc = runOptions.StopCallback
z.startFunc = runOptions.StartCallback

Expand Down Expand Up @@ -202,7 +202,7 @@ func (z *Ziggurat) MetricPublisher() ztype.MetricPublisher {
return z.metricPublisher
}

func (z *Ziggurat) HTTPServer() ztype.HttpServer {
func (z *Ziggurat) HTTPServer() ztype.Server {
return z.httpServer
}

Expand Down

0 comments on commit fa38348

Please sign in to comment.