Documentation ¶
Index ¶
- Constants
- Variables
- func FileServerWith404(root http.FileSystem, handler404 FSHandler404) http.Handler
- func InterceptHttp(underlying http.Handler, interceptors ...HttpInterceptor) http.Handler
- func LoadOrCreateSelfSignedCA(opts ...caOption) (instance *ca, fromCache bool, err error)
- func LogRepeatChanges() grpc.StreamServerInterceptor
- func Serve(opts ...ConfigOption) error
- func SetupHttpServer(server *grpc.Server) *http.Server
- type App
- type Config
- type ConfigOption
- func NoGrpcWeb() ConfigOption
- func NoHealth() ConfigOption
- func NoPlainGrpcWeb() ConfigOption
- func NoReflection() ConfigOption
- func WithApis(api ...server.GrpcApi) ConfigOption
- func WithCertCacheDir(certCacheDir string) ConfigOption
- func WithContext(ctx context.Context) ConfigOption
- func WithDefaultName(defaultName string) ConfigOption
- func WithForceCertGen() ConfigOption
- func WithGrpcAddress(address string) ConfigOption
- func WithGrpcTls(c *tls.Config) ConfigOption
- func WithHostedDir(dir string) ConfigOption
- func WithHostedFS(fs fs.FS) ConfigOption
- func WithHostedFSNotFound(html []byte) ConfigOption
- func WithHttpAddress(address string) ConfigOption
- func WithHttpHealth(path string) ConfigOption
- func WithHttpTls(c *tls.Config) ConfigOption
- func WithHttpsAddress(address string) ConfigOption
- func WithInsecure() ConfigOption
- func WithMTLS() ConfigOption
- type FSHandler404
- type HttpInterceptor
Constants ¶
const (
CertDir = "sc-playground/certs"
)
Variables ¶
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 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
Types ¶
type App ¶
type App struct { Apis []server.GrpcApi Host http.FileSystem TlsConfig *tls.Config // contains filtered or unexported fields }
func (*App) ServeAddress ¶
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 ¶
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