Skip to content
Permalink
f92229e1fe
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
62 lines (57 sloc) 1.25 KB
package main
import (
"context"
"github.com/getsentry/sentry-go"
"go.uber.org/fx"
"go.uber.org/zap"
"time"
"vlink.dev/eoefans/internal/app/api"
"vlink.dev/eoefans/internal/app/api/service"
"vlink.dev/eoefans/internal/launcher"
"vlink.dev/eoefans/internal/pkg/database"
"vlink.dev/eoefans/internal/pkg/httpserver"
"vlink.dev/eoefans/internal/pkg/log"
)
func main() {
launcher.Run(newAPI())
}
func newAPI() fx.Option {
return fx.Options(
database.Provide(),
httpserver.Provide(),
api.Provide(),
fx.Invoke(lc),
)
}
func lc(
lifecycle fx.Lifecycle,
ginServer *httpserver.Server,
randPicsCache *service.RandomPicsCache,
logger *zap.Logger,
client *sentry.Client,
sentryCfg *log.SentryConfig,
) {
lifecycle.Append(fx.Hook{
OnStart: func(ctx context.Context) error {
*logger = *log.ModifyToSentryLogger(logger, sentryCfg, client)
return nil
},
OnStop: func(ctx context.Context) error {
client.Flush(2 * time.Second)
return nil
},
})
lifecycle.Append(fx.Hook{
OnStart: func(ctx context.Context) error {
return ginServer.Start()
},
OnStop: func(ctx context.Context) error {
return ginServer.Stop()
},
})
lifecycle.Append(fx.Hook{
OnStart: func(ctx context.Context) error {
return randPicsCache.Run()
},
})
}