mirror of
https://github.com/opencloud-eu/opencloud.git
synced 2026-05-25 14:39:00 -05:00
Revive http service for serving assets. Streamlined flagset.
This commit is contained in:
@@ -14,7 +14,7 @@ type Option func(o *Options)
|
||||
|
||||
// Options defines the available options for this package.
|
||||
type Options struct {
|
||||
Namespace string
|
||||
Name string
|
||||
Logger log.Logger
|
||||
Context context.Context
|
||||
Config *config.Config
|
||||
@@ -40,6 +40,13 @@ func Logger(val log.Logger) Option {
|
||||
}
|
||||
}
|
||||
|
||||
// Name provides a name for the service.
|
||||
func Name(val string) Option {
|
||||
return func(o *Options) {
|
||||
o.Name = val
|
||||
}
|
||||
}
|
||||
|
||||
// Context provides a function to set the context option.
|
||||
func Context(val context.Context) Option {
|
||||
return func(o *Options) {
|
||||
@@ -67,10 +74,3 @@ func Flags(val []cli.Flag) Option {
|
||||
o.Flags = append(o.Flags, val...)
|
||||
}
|
||||
}
|
||||
|
||||
// Namespace provides a function to set the Namespace option.
|
||||
func Namespace(val string) Option {
|
||||
return func(o *Options) {
|
||||
o.Namespace = val
|
||||
}
|
||||
}
|
||||
|
||||
+66
-48
@@ -1,56 +1,74 @@
|
||||
package http
|
||||
|
||||
// import (
|
||||
// svc "github.com/owncloud/ocis-settings/pkg/service/v0"
|
||||
// "github.com/owncloud/ocis-settings/pkg/version"
|
||||
// "github.com/owncloud/ocis-pkg/v2/middleware"
|
||||
// "github.com/owncloud/ocis-pkg/v2/service/http"
|
||||
// )
|
||||
import (
|
||||
"github.com/go-chi/chi"
|
||||
"github.com/owncloud/ocis-pkg/v2/middleware"
|
||||
"github.com/owncloud/ocis-pkg/v2/service/http"
|
||||
"github.com/owncloud/ocis-settings/pkg/assets"
|
||||
"github.com/owncloud/ocis-settings/pkg/proto/v0"
|
||||
svc "github.com/owncloud/ocis-settings/pkg/service/v0"
|
||||
"github.com/owncloud/ocis-settings/pkg/version"
|
||||
)
|
||||
|
||||
// // Server initializes the http service and server.
|
||||
// func Server(opts ...Option) (http.Service, error) {
|
||||
// options := newOptions(opts...)
|
||||
// Server initializes the http service and server.
|
||||
func Server(opts ...Option) http.Service {
|
||||
options := newOptions(opts...)
|
||||
|
||||
// service := http.NewService(
|
||||
// http.Logger(options.Logger),
|
||||
// http.Name("settings"),
|
||||
// http.Version(version.String),
|
||||
// http.Namespace(options.Config.HTTP.Namespace),
|
||||
// http.Address(options.Config.HTTP.Addr),
|
||||
// http.Context(options.Context),
|
||||
// http.Flags(options.Flags...),
|
||||
// )
|
||||
service := http.NewService(
|
||||
http.Logger(options.Logger),
|
||||
http.Name(options.Name),
|
||||
http.Version(version.String),
|
||||
http.Address(options.Config.HTTP.Addr),
|
||||
http.Namespace(options.Config.HTTP.Namespace),
|
||||
http.Context(options.Context),
|
||||
http.Flags(options.Flags...),
|
||||
)
|
||||
|
||||
// handle := svc.NewService(
|
||||
// svc.Logger(options.Logger),
|
||||
// svc.Config(options.Config),
|
||||
// svc.Middleware(
|
||||
// middleware.RealIP,
|
||||
// middleware.RequestID,
|
||||
// middleware.Cache,
|
||||
// middleware.Cors,
|
||||
// middleware.Secure,
|
||||
// middleware.Version(
|
||||
// "settings",
|
||||
// version.String,
|
||||
// ),
|
||||
// middleware.Logger(
|
||||
// options.Logger,
|
||||
// ),
|
||||
// ),
|
||||
// )
|
||||
handle := svc.NewService(options.Config)
|
||||
|
||||
// {
|
||||
// handle = svc.NewInstrument(handle, options.Metrics)
|
||||
// handle = svc.NewLogging(handle, options.Logger)
|
||||
// handle = svc.NewTracing(handle)
|
||||
// }
|
||||
{
|
||||
handle = svc.NewInstrument(handle, options.Metrics)
|
||||
handle = svc.NewLogging(handle, options.Logger)
|
||||
handle = svc.NewTracing(handle)
|
||||
}
|
||||
|
||||
// service.Handle(
|
||||
// "/",
|
||||
// handle,
|
||||
// )
|
||||
mux := chi.NewMux()
|
||||
|
||||
// service.Init()
|
||||
// return service, nil
|
||||
// }
|
||||
mux.Use(middleware.RealIP)
|
||||
mux.Use(middleware.RequestID)
|
||||
mux.Use(middleware.Cache)
|
||||
mux.Use(middleware.Cors)
|
||||
mux.Use(middleware.Secure)
|
||||
|
||||
mux.Use(middleware.Version(
|
||||
"settings",
|
||||
version.String,
|
||||
))
|
||||
|
||||
mux.Use(middleware.Logger(
|
||||
options.Logger,
|
||||
))
|
||||
|
||||
mux.Use(middleware.Static(
|
||||
options.Config.HTTP.Root,
|
||||
assets.New(
|
||||
assets.Logger(options.Logger),
|
||||
assets.Config(options.Config),
|
||||
),
|
||||
))
|
||||
|
||||
mux.Route(options.Config.HTTP.Root, func(r chi.Router) {
|
||||
proto.RegisterBundleServiceWeb(
|
||||
r,
|
||||
handle,
|
||||
)
|
||||
})
|
||||
|
||||
service.Handle(
|
||||
"/",
|
||||
mux,
|
||||
)
|
||||
|
||||
service.Init()
|
||||
return service
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user