service

package
v0.12.5 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 17, 2019 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Copyright 2019 SpotHero

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Name        string                // Name of the application
	Environment string                // Environment where the server is running
	Version     string                // Semantic Version of the application
	GitSHA      string                // GitSHA of the application when compiled
	Registry    prometheus.Registerer // The Prometheus Registry to use. If nil, the global registry is used by default.
}

Config defines service level configuration for HTTP servers

func (Config) CheckFlags

func (c Config) CheckFlags() error

CheckFlags ensures that the Service Config contains all necessary configuration for use at runtime. An error is returned describing any missing fields.

func (*Config) RegisterFlags

func (c *Config) RegisterFlags(flags *pflag.FlagSet)

RegisterFlags registers Service flags with pflags

type HTTPConfig

type HTTPConfig struct {
	Config
	PreStart     func(ctx context.Context, router *mux.Router, server *http.Server) // A function to be called before starting the web server
	PostShutdown func(ctx context.Context)                                          // A function to be called before stopping the web server
}

func (HTTPConfig) ServerCmd

func (hc HTTPConfig) ServerCmd(shortDescript, longDescript string, newService func(HTTPConfig) HTTPService) *cobra.Command

ServerCmd creates and returns a Cobra and Viper command preconfigured to run a production-quality HTTP server. This method takes a function that instantiates a HTTPService interface that passes through the HTTPConfig object to the constructor after all values are populated from the CLI and/or environment variables so that values configured by this package are accessible downstream.

Note that this function returns the Default HTTP server for use at SpotHero. Consumers of the tools libraries are free to define their own server entrypoints if desired. This function is provided as a convenience function that should satisfy most use cases Note that Version and GitSHA *must be specified* before calling this function.

type HTTPService added in v0.6.0

type HTTPService interface {
	RegisterHandlers(router *mux.Router)
}

HTTPService implementers register HTTP routes with a mux router.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL