Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
var MigrateCmd = &cobra.Command{ Use: "migrate", Short: "A brief description of your command", Long: `A longer description that spans multiple lines and likely contains examples and usage of using your command. For example: Cobra is a CLI library for Go that empowers applications. This application is a tool to generate the needed files to quickly create a Cobra application.`, Run: func(cmd *cobra.Command, args []string) { log.Info("migrate called") db, err := sql.Open("postgres", cmd.Flags().Lookup("postgres").Value.String()) if err != nil { panic(err) } defer db.Close() level, _ := strconv.Atoi(cmd.Flags().Lookup("target").Value.String()) err = ApplyMigrationsUp(db, "./migrations/", uint(level)) if err != nil { panic(err) } }, }
migrateCmd represents the migrate command
var ServeCmd = &cobra.Command{ Use: "serve", Short: "Start the http server", PreRun: func(cmd *cobra.Command, args []string) { log.Debug("Enumerating flags:") if cmd.HasFlags() { cmd.Flags().VisitAll(func(flag *pflag.Flag) { log.Debug(flag.Name, " ", flag.Value) }) } }, Run: func(cmd *cobra.Command, args []string) { log.Info("Starting the http server in the chassis") }, }
serveCmd represents the serve command
Functions ¶
func ApplyMigrationsUp ¶
ApplyMigrationsUp applies the database migrations for Postgres Databases up to the latest version
func ConnectDB ¶
ConnectDB connects to the database and returns a pointer to the connection object. It is the caller's responsibility to close the connection. The flavor parameter is the name of the database driver to use, e.g. "postgres". The uri parameter is the connection string to use, e.g. "host=localhost port=5432 user=postgres password=postgres dbname=postgres sslmode=disable".
Types ¶
type Microservice ¶
type Microservice struct { ExecutableName string InstanceName string InstaceID uuid.UUID Version string Router *gin.Engine DB *sqlx.DB Config Config }
func NewMicroservice ¶
func NewMicroservice(config Config) *Microservice
NewMicroservice initializes the bare microservice.
func (*Microservice) AddRoute ¶
func (m *Microservice) AddRoute(method string, path string, handler gin.HandlerFunc)
func (*Microservice) Init ¶
func (m *Microservice) Init()
Init is a convenience function. Developers that want to accept all reasonable defaults can use it to call the other initialization functions in one go.
func (*Microservice) InitPostgres ¶
func (m *Microservice) InitPostgres(config PostgresConfig)
InitPostgres initializes the connection to Postgres
func (*Microservice) Serve ¶
func (m *Microservice) Serve()
type MicroserviceConfig ¶
func DefaultMicroserviceConfig ¶
func DefaultMicroserviceConfig() MicroserviceConfig
func (*MicroserviceConfig) GetListenAddress ¶
func (c *MicroserviceConfig) GetListenAddress() string
func (*MicroserviceConfig) GetPostgresConfig ¶
func (c *MicroserviceConfig) GetPostgresConfig() string
type PostgresConfig ¶
type PostgresConfig struct { ConnectionString string `mapstructure:"postgres_connection_string"` // Connection string MaxOpenConnections int `mapstructure:"postgres_max_open_connections"` // Maximum number of open connections MaxIdleConnections int `mapstructure:"postgres_max_idle_connections"` // Maximum number of idle connections ConnectionMaxLifetime int `mapstructure:"postgres_connection_max_lifetime"` // Maximum connection lifetime (seconds) ConnectionMaxIdleTime int `mapstructure:"postgres_connection_max_idle_time"` // Maximum connection idle time (seconds) }
PostgresConfig is a struct that holds the configuration for the Postgres database
var DBConfig PostgresConfig
func DefaultPostgresConfig ¶
func DefaultPostgresConfig() PostgresConfig
Our Sensible defaults are set in code here and can be overridden by instances
func ParsePostgresConfig ¶
func ParsePostgresConfig(config string) PostgresConfig