-
Notifications
You must be signed in to change notification settings - Fork 2
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
13 changed files
with
145 additions
and
40 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 |
---|---|---|
|
@@ -6,3 +6,6 @@ | |
.config/genenv.local.sh | ||
|
||
node_modules/ | ||
|
||
# Generated go files. | ||
_gen.go |
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,22 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/labstack/echo/v4" | ||
"github.com/prismelabs/prismeanalytics/internal/config" | ||
"github.com/prismelabs/prismeanalytics/internal/log" | ||
) | ||
|
||
type App struct { | ||
cfg config.Config | ||
echo *echo.Echo | ||
logger log.Logger | ||
} | ||
|
||
// ProvideApp is a wire provider for App. | ||
func ProvideApp(cfg config.Config, e *echo.Echo, logger StandardLogger) App { | ||
return App{ | ||
cfg: cfg, | ||
echo: e, | ||
logger: logger.Logger, | ||
} | ||
} |
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,15 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/prismelabs/prismeanalytics/internal/config" | ||
"github.com/prismelabs/prismeanalytics/internal/log" | ||
) | ||
|
||
// ProvideConfig is a wire provider config.Config. | ||
func ProvideConfig(logger log.Logger) config.Config { | ||
logger.Info().Msg("loading configuration...") | ||
cfg := config.FromEnv() | ||
logger.Info().Any("config", cfg).Msg("configuration successfully loaded.") | ||
|
||
return cfg | ||
} |
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,24 @@ | ||
package main | ||
|
||
import ( | ||
"github.com/labstack/echo/v4" | ||
"github.com/prismelabs/prismeanalytics/internal/config" | ||
"github.com/prismelabs/prismeanalytics/internal/middlewares" | ||
) | ||
|
||
// ProvideEcho is a wire provider for echo.Echo. It setup middleware and handlers. | ||
func ProvideEcho(cfg config.Config, accessLogger AccessLogger) *echo.Echo { | ||
e := echo.New() | ||
if cfg.Server.TrustProxy { | ||
e.IPExtractor = echo.ExtractIPFromXFFHeader() | ||
} else { | ||
e.IPExtractor = echo.ExtractIPDirect() | ||
} | ||
e.HideBanner = true | ||
e.HidePort = true | ||
|
||
e.Use(middlewares.RequestId(cfg.Server)) | ||
e.Use(middlewares.AccessLog(accessLogger.Logger)) | ||
|
||
return e | ||
} |
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,39 @@ | ||
package main | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/prismelabs/prismeanalytics/internal/config" | ||
"github.com/prismelabs/prismeanalytics/internal/log" | ||
) | ||
|
||
// StandardLogger is the application logger. | ||
type StandardLogger struct { | ||
log.Logger | ||
} | ||
|
||
// ProvideStandardLogger is a wire provider for StandardLogger. | ||
func ProvideStandardLogger(cfg config.Config) StandardLogger { | ||
logger := log.NewLogger("app", os.Stderr, cfg.Server.Debug) | ||
log.TestLoggers(logger) | ||
|
||
return StandardLogger{logger} | ||
} | ||
|
||
type AccessLogger struct { | ||
log.Logger | ||
} | ||
|
||
// ProvideAccessLogger is a wire provider for AccessLogger. | ||
func ProvideAccessLogger(cfg config.Config, logger StandardLogger) AccessLogger { | ||
// Open access log file. | ||
accessLogFile, err := os.OpenFile(cfg.Server.AccessLog, os.O_CREATE|os.O_WRONLY|os.O_APPEND, os.ModePerm) | ||
if err != nil { | ||
logger.Panic().Err(err).Msgf("failed to open access log file: %v", cfg.Server.AccessLog) | ||
} | ||
|
||
accessLogger := log.NewLogger("access_log", accessLogFile, cfg.Server.Debug) | ||
log.TestLoggers(accessLogger) | ||
|
||
return AccessLogger{accessLogger} | ||
} |
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,21 @@ | ||
//go:build wireinject | ||
// +build wireinject | ||
|
||
package main | ||
|
||
import ( | ||
"github.com/google/wire" | ||
"github.com/prismelabs/prismeanalytics/internal/log" | ||
"github.com/prismelabs/prismeanalytics/internal/middlewares" | ||
) | ||
|
||
func initialize(logger log.Logger) App { | ||
wire.Build( | ||
ProvideConfig, | ||
ProvideStandardLogger, | ||
ProvideAccessLogger, | ||
ProvideEcho, | ||
ProvideApp, | ||
) | ||
return App{} | ||
} |
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 |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
go | ||
gopls | ||
golangci-lint | ||
wire | ||
bunyan-rs | ||
entr | ||
bun | ||
|
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