Possibilities:
-
Running a gRPC server with metrics for Prometheus (see config and options)
-
Working with the database via GORM with support for database migration via Goose with the ability to specify migration files from the file system or via
embed.FS
-
Using the gocron task scheduler
-
Different log output format based on Zap, depending on the launch environment - launch in container or not
-
Getting settings via environment variables
-
db/config.go - more details in the db/README.adoc
To read the configuration from the environment, it is recommended to use the method ReadEnvConfig()
see TODO.adoc
Minimum code configuration to run
func main() {
_ := NewServiceWithEnvironment(context.Background(), zap.NewProductionConfig()).Run()
}
Configuration with the transfer of migration scripts for database migration via Embedded FS
import "embed"
//go:embed folder/*.sql
var embedMigrations embed.FS
func main(){
_ := NewServiceWithEnvironment(context.Background(), zap.NewProductionConfig()).
InitDB(&embedMigrations).
Run()
}
alternative:
import "embed"
//go:embed folder/*.sql
var embedMigrations embed.FS
func main(){
srv := NewServiceWithEnvironment(context.Background(), zap.NewProductionConfig())
gormDB := srv.GetGormWithEmbeddedMigrations(&embedMigrations)
srv.Run()
}
Specifying custom metrics for Prometheus for gRPC server
import grpcPrometheus "github.com/grpc-ecosystem/go-grpc-middleware/providers/prometheus"
func main() {
_ := NewServiceWithEnvironment(context.Background(), zap.NewProductionConfig()).
InitGrpcServerMetrics(grpcPrometheus.WithServerHandlingTimeHistogram()).
Run()
}