run

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Oct 12, 2022 License: MIT Imports: 40 Imported by: 0

Documentation

Index

Constants

View Source
const (
	CertDir = "sc-playground/certs"
)

Variables

View Source
var DefaultOpts = []ConfigOption{
	WithContext(context.Background()),
	WithGrpcAddress(":9090"),
	WithHttpAddress(":8080"),
	WithHttpsAddress(":8443"),
}

Functions

func FileServerWith404 added in v0.0.4

func FileServerWith404(root http.FileSystem, handler404 FSHandler404) http.Handler

FileServerWith404 wraps the http.FileServer checking to see if the url path exists first. If the file fails to exist it calls the supplied FSHandle404 function The implementation can choose to either modify the request, e.g. change the URL path and return true to have the default FileServer handling to still take place, or return false to stop further processing, for example if you wanted to write a custom response e.g. redirects to root and continues the file serving handler chain

func fileSystem404(w http.ResponseWriter, r *http.Request) (doDefaultFileServe bool) {
	//if not found redirect to /
	r.URL.Path = "/"
	return true
}

Use the same as you would with a http.FileServer e.g.

r.Handle("/", http.StripPrefix("/", mw.FileServerWith404(http.Dir("./staticDir"), fileSystem404)))

func InterceptHttp

func InterceptHttp(underlying http.Handler, interceptors ...HttpInterceptor) http.Handler

func LoadOrCreateSelfSignedCA

func LoadOrCreateSelfSignedCA(opts ...caOption) (instance *ca, fromCache bool, err error)

func LogRepeatChanges added in v0.0.4

func LogRepeatChanges() grpc.StreamServerInterceptor

LogRepeatChanges returns a StreamServerInterceptor that logs out when streams return the same message more than 10 times in a row. The interceptor is aware of the patterns used in Smart Core and ignores differences in the PullResponse.Change.change_time property.

func Serve

func Serve(opts ...ConfigOption) error

func SetupHttpServer

func SetupHttpServer(server *grpc.Server) *http.Server

Types

type App

type App struct {
	Apis []server.GrpcApi
	Host http.FileSystem

	TlsConfig *tls.Config
	// contains filtered or unexported fields
}

func NewApp

func NewApp(ctx context.Context) *App

func (*App) HostDir

func (a *App) HostDir(dir string)

func (*App) ServeAddress

func (a *App) ServeAddress(addr string) error

func (*App) SetupGrpcServer

func (a *App) SetupGrpcServer(apis ...server.GrpcApi) *grpc.Server

func (*App) WithApis

func (a *App) WithApis(apis ...server.GrpcApi)

func (*App) WithServerCert

func (a *App) WithServerCert(cert tls.Certificate)

WithServerCert causes the gRPC server to only accept tls connections. Calling this forces the gRPC server to enable server TLS. See: grpc.Creds

type Config

type Config struct {
	// contains filtered or unexported fields
}

func (*Config) MarshalJSON

func (c *Config) MarshalJSON() ([]byte, error)

type ConfigOption

type ConfigOption func(*Config)
var NilConfigOption ConfigOption = func(config *Config) {

}

func NoGrpcWeb

func NoGrpcWeb() ConfigOption

func NoHealth

func NoHealth() ConfigOption

func NoPlainGrpcWeb

func NoPlainGrpcWeb() ConfigOption

func NoReflection

func NoReflection() ConfigOption

func WithApis

func WithApis(api ...server.GrpcApi) ConfigOption

func WithCertCacheDir

func WithCertCacheDir(certCacheDir string) ConfigOption

func WithContext

func WithContext(ctx context.Context) ConfigOption

func WithDefaultName

func WithDefaultName(defaultName string) ConfigOption

WithDefaultName configures the application with a default Smart Core name. The defaultName will be used as the default for requests that don't specify a name.

func WithForceCertGen

func WithForceCertGen() ConfigOption

func WithGrpcAddress

func WithGrpcAddress(address string) ConfigOption

func WithGrpcTls

func WithGrpcTls(c *tls.Config) ConfigOption

func WithHostedDir

func WithHostedDir(dir string) ConfigOption

func WithHostedFS

func WithHostedFS(fs fs.FS) ConfigOption

func WithHostedFSNotFound added in v0.0.4

func WithHostedFSNotFound(html []byte) ConfigOption

func WithHttpAddress

func WithHttpAddress(address string) ConfigOption

func WithHttpHealth

func WithHttpHealth(path string) ConfigOption

func WithHttpTls

func WithHttpTls(c *tls.Config) ConfigOption

func WithHttpsAddress

func WithHttpsAddress(address string) ConfigOption

func WithInsecure

func WithInsecure() ConfigOption

func WithMTLS

func WithMTLS() ConfigOption

type FSHandler404 added in v0.0.4

type FSHandler404 = func(w http.ResponseWriter, r *http.Request) (doDefaultFileServe bool)

FSHandler404 provides the function signature for passing to the FileServerWith404

type HttpInterceptor

type HttpInterceptor func(w http.ResponseWriter, r *http.Request, next http.Handler)

Jump to

Keyboard shortcuts

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