-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
367 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/maestre3d/alexandria/category-service/pkg/dep" | ||
"github.com/oklog/run" | ||
"log" | ||
"net" | ||
"net/http" | ||
"os" | ||
"os/signal" | ||
"syscall" | ||
) | ||
|
||
func main() { | ||
ctx, _ := context.WithCancel(context.Background()) | ||
dep.SetContext(ctx) | ||
|
||
proxy, cleanup, err := dep.InjectTransportProxy() | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
defer func() { | ||
log.Print("stopping services") | ||
cleanup() | ||
}() | ||
|
||
var g run.Group | ||
{ | ||
l, err := net.Listen("tcp", proxy.HTTP.Server.Addr) | ||
if err != nil { | ||
log.Fatal(err) | ||
} | ||
|
||
g.Add(func() error { | ||
log.Print("starting http server") | ||
return http.Serve(l, proxy.HTTP.Server.Handler) | ||
}, func(err error) { | ||
if err != nil { | ||
log.Print(err) | ||
} | ||
log.Print(l.Close()) | ||
}) | ||
} | ||
{ | ||
// Set up signal bind | ||
var ( | ||
cancelInterrupt = make(chan struct{}) | ||
c = make(chan os.Signal, 2) | ||
) | ||
defer close(c) | ||
|
||
g.Add(func() error { | ||
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM) | ||
select { | ||
case sig := <-c: | ||
return fmt.Errorf("received signal %s", sig) | ||
case <-cancelInterrupt: | ||
return nil | ||
} | ||
}, func(error) { | ||
// Cancel root context, propagate cancellation | ||
// cancel() | ||
close(cancelInterrupt) | ||
}) | ||
} | ||
|
||
log.Fatal(g.Run()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
//+build wireinject | ||
|
||
package dep | ||
|
||
import ( | ||
"context" | ||
"github.com/alexandria-oss/core/config" | ||
"github.com/alexandria-oss/core/logger" | ||
"github.com/go-kit/kit/log" | ||
"github.com/google/wire" | ||
"github.com/maestre3d/alexandria/category-service/internal/dependency" | ||
"github.com/maestre3d/alexandria/category-service/pkg/middleware" | ||
"github.com/maestre3d/alexandria/category-service/pkg/service" | ||
"github.com/maestre3d/alexandria/category-service/pkg/transport" | ||
"github.com/maestre3d/alexandria/category-service/pkg/transport/handler" | ||
) | ||
|
||
var ctx = context.Background() | ||
|
||
var httpCategorySet = wire.NewSet( | ||
provideContext, | ||
logger.NewZapLogger, | ||
provideCategoryService, | ||
handler.NewCategoryHTTP, | ||
) | ||
|
||
var transportProxySet = wire.NewSet( | ||
httpCategorySet, | ||
provideHandlers, | ||
config.NewKernel, | ||
transport.NewHTTPServer, | ||
transport.NewProxy, | ||
) | ||
|
||
func SetContext(rootCtx context.Context) { | ||
ctx = rootCtx | ||
} | ||
|
||
func provideContext() context.Context { | ||
return ctx | ||
} | ||
|
||
func provideCategoryService(ctx context.Context, logger log.Logger) (service.Category, func(), error) { | ||
dependency.SetContext(ctx) | ||
|
||
useCase, cleanup, err := dependency.InjectCategoryUseCase() | ||
svc := middleware.WrapCategoryMiddleware(useCase, logger) | ||
|
||
return svc, cleanup, err | ||
} | ||
|
||
func provideHandlers(category *handler.CategoryHTTP) []transport.Handler { | ||
return []transport.Handler{category} | ||
} | ||
|
||
func InjectTransportProxy() (*transport.Proxy, func(), error) { | ||
wire.Build(transportProxySet) | ||
return &transport.Proxy{}, nil, nil | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.