Use new package structuring, embed existing extensions

This commit is contained in:
Thomas Boerger
2019-12-10 15:24:01 +01:00
parent 6b6b1d8b66
commit 1612e4a841
30 changed files with 2045 additions and 278 deletions

View File

@@ -1,29 +0,0 @@
[run]
watch_all = true
watch_dirs = ["cmd", "pkg"]
watch_exts = [".go"]
ignore = [".git", "bin", "dist"]
ignore_files = []
build_delay = 1500
interrupt_timout = 15
graceful_kill = false
init_cmds = [
["make", "build"],
[
"./bin/ocis",
"--log-level",
"debug",
"server"
]
]
cmds = [
["make", "build"],
[
"./bin/ocis",
"--log-level",
"debug",
"server"
]
]

8
.codacy.yml Normal file
View File

@@ -0,0 +1,8 @@
---
exclude_paths:
- CHANGELOG.md
- changelog/**
- docs/**
- pkg/proto/**
...

View File

@@ -449,10 +449,33 @@ def changelog(ctx):
'os': 'linux',
'arch': 'amd64',
},
'clone': {
'disable': True,
},
'steps': [
{
'name': 'clone',
'image': 'plugins/git-action:1',
'pull': 'always',
'settings': {
'actions': [
'clone',
],
'remote': 'https://github.com/%s' % (ctx.repo.slug),
'branch': ctx.build.branch if ctx.build.event == 'pull_request' else 'master',
'path': '/drone/src',
'netrc_machine': 'github.com',
'netrc_username': {
'from_secret': 'github_username',
},
'netrc_password': {
'from_secret': 'github_token',
},
},
},
{
'name': 'generate',
'image': 'toolhippie/calens:latest',
'image': 'webhippie/golang:1.13',
'pull': 'always',
'commands': [
'make changelog',
@@ -460,7 +483,7 @@ def changelog(ctx):
},
{
'name': 'output',
'image': 'toolhippie/calens:latest',
'image': 'webhippie/golang:1.13',
'pull': 'always',
'commands': [
'cat CHANGELOG.md',

View File

@@ -1 +1,18 @@
# Changelog
# Changelog for unreleased
The following sections list the changes for unreleased.
## Summary
* Chg #2: Initial release of basic version
## Details
* Change #2: Initial release of basic version
Just prepared an initial basic version which simply embeds the minimum of required services in
the context of the ownCloud Infinite Scale project.
https://github.com/owncloud/ocis/issues/2

View File

@@ -6,10 +6,16 @@ DIST := dist
ifeq ($(OS), Windows_NT)
EXECUTABLE := $(NAME).exe
HAS_GORUNPKG := $(shell where gorunpkg)
UNAME := Windows
else
EXECUTABLE := $(NAME)
HAS_GORUNPKG := $(shell command -v gorunpkg)
UNAME := $(shell uname -s)
endif
ifeq ($(UNAME), Darwin)
GOBUILD ?= go build -i
else
GOBUILD ?= go build
endif
PACKAGES ?= $(shell go list ./...)
@@ -39,6 +45,7 @@ ifndef DATE
endif
LDFLAGS += -s -w -X "$(IMPORT)/pkg/version.String=$(VERSION)" -X "$(IMPORT)/pkg/version.Date=$(DATE)"
GCFLAGS += all=-N -l
.PHONY: all
all: build
@@ -61,34 +68,37 @@ vet:
go vet $(PACKAGES)
.PHONY: staticcheck
staticcheck: gorunpkg
gorunpkg honnef.co/go/tools/cmd/staticcheck -tags '$(TAGS)' $(PACKAGES)
staticcheck:
go run honnef.co/go/tools/cmd/staticcheck -tags '$(TAGS)' $(PACKAGES)
.PHONY: lint
lint: gorunpkg
for PKG in $(PACKAGES); do gorunpkg golang.org/x/lint/golint -set_exit_status $$PKG || exit 1; done;
lint:
for PKG in $(PACKAGES); do go run golang.org/x/lint/golint -set_exit_status $$PKG || exit 1; done;
.PHONY: generate
generate: gorunpkg
generate:
go generate $(GENERATE)
.PHONY: changelog
changelog: gorunpkg
gorunpkg github.com/restic/calens >| CHANGELOG.md
changelog:
go run github.com/restic/calens >| CHANGELOG.md
.PHONY: test
test: gorunpkg
gorunpkg github.com/haya14busa/goverage -v -coverprofile coverage.out $(PACKAGES)
test:
go run github.com/haya14busa/goverage -v -coverprofile coverage.out $(PACKAGES)
.PHONY: install
install: $(SOURCES)
go install -v -tags '$(TAGS)' -ldflags '$(LDFLAGS)' ./cmd/$(NAME)
.PHONY: build
build: $(BIN)/$(EXECUTABLE)
build: $(BIN)/$(EXECUTABLE) $(BIN)/$(EXECUTABLE)-debug
$(BIN)/$(EXECUTABLE): $(SOURCES)
go build -i -v -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -o $@ ./cmd/$(NAME)
$(GOBUILD) -v -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -o $@ ./cmd/$(NAME)
$(BIN)/$(EXECUTABLE)-debug: $(SOURCES)
$(GOBUILD) -v -tags '$(TAGS)' -ldflags '$(LDFLAGS)' -gcflags '$(GCFLAGS)' -o $@ ./cmd/$(NAME)
.PHONY: release
release: release-dirs release-linux release-windows release-darwin release-copy release-check
@@ -98,16 +108,16 @@ release-dirs:
mkdir -p $(DIST)/binaries $(DIST)/release
.PHONY: release-linux
release-linux: gorunpkg release-dirs
gorunpkg github.com/mitchellh/gox -tags 'netgo $(TAGS)' -ldflags '-extldflags "-static" $(LDFLAGS)' -os 'linux' -arch 'amd64 386 arm64 arm' -output '$(DIST)/binaries/$(EXECUTABLE)-$(OUTPUT)-{{.OS}}-{{.Arch}}' ./cmd/$(NAME)
release-linux: release-dirs
go run github.com/mitchellh/gox -tags 'netgo $(TAGS)' -ldflags '-extldflags "-static" $(LDFLAGS)' -os 'linux' -arch 'amd64 386 arm64 arm' -output '$(DIST)/binaries/$(EXECUTABLE)-$(OUTPUT)-{{.OS}}-{{.Arch}}' ./cmd/$(NAME)
.PHONY: release-windows
release-windows: gorunpkg release-dirs
gorunpkg github.com/mitchellh/gox -tags 'netgo $(TAGS)' -ldflags '-extldflags "-static" $(LDFLAGS)' -os 'windows' -arch 'amd64' -output '$(DIST)/binaries/$(EXECUTABLE)-$(OUTPUT)-{{.OS}}-{{.Arch}}' ./cmd/$(NAME)
release-windows: release-dirs
go run github.com/mitchellh/gox -tags 'netgo $(TAGS)' -ldflags '-extldflags "-static" $(LDFLAGS)' -os 'windows' -arch 'amd64' -output '$(DIST)/binaries/$(EXECUTABLE)-$(OUTPUT)-{{.OS}}-{{.Arch}}' ./cmd/$(NAME)
.PHONY: release-darwin
release-darwin: gorunpkg release-dirs
gorunpkg github.com/mitchellh/gox -tags 'netgo $(TAGS)' -ldflags '$(LDFLAGS)' -os 'darwin' -arch 'amd64' -output '$(DIST)/binaries/$(EXECUTABLE)-$(OUTPUT)-{{.OS}}-{{.Arch}}' ./cmd/$(NAME)
release-darwin: release-dirs
go run github.com/mitchellh/gox -tags 'netgo $(TAGS)' -ldflags '$(LDFLAGS)' -os 'darwin' -arch 'amd64' -output '$(DIST)/binaries/$(EXECUTABLE)-$(OUTPUT)-{{.OS}}-{{.Arch}}' ./cmd/$(NAME)
.PHONY: release-copy
release-copy:
@@ -120,12 +130,10 @@ release-check:
.PHONY: release-finish
release-finish: release-copy release-check
.PHONY: gorunpkg
gorunpkg:
ifndef HAS_GORUNPKG
go get -u github.com/vektah/gorunpkg
endif
.PHONY: docs
docs:
cd docs; hugo
.PHONY: watch
watch:
go run github.com/cespare/reflex -c reflex.conf

View File

@@ -15,7 +15,7 @@ You can download prebuilt binaries from the GitHub releases or from our [downloa
## Development
Make sure you have a working Go environment, for further reference or a guide take a look at the [install instructions](http://golang.org/doc/install.html). This project requires Go >= v1.12.
Make sure you have a working Go environment, for further reference or a guide take a look at the [install instructions](http://golang.org/doc/install.html). This project requires Go >= v1.13.
```console
git clone https://github.com/owncloud/ocis.git

View File

@@ -7,7 +7,7 @@ import (
)
func main() {
if err := command.Root().Execute(); err != nil {
if err := command.Execute(); err != nil {
os.Exit(1)
}
}

View File

@@ -7,7 +7,7 @@ RUN apk update && \
echo 'hosts: files dns' >| /etc/nsswitch.conf
LABEL maintainer="ownCloud GmbH <devops@owncloud.com>" \
org.label-schema.name="oCIS" \
org.label-schema.name="ownCloud Infinite Scale" \
org.label-schema.vendor="ownCloud GmbH" \
org.label-schema.schema-version="1.0"

View File

@@ -7,7 +7,7 @@ RUN apk update && \
echo 'hosts: files dns' >| /etc/nsswitch.conf
LABEL maintainer="ownCloud GmbH <devops@owncloud.com>" \
org.label-schema.name="oCIS" \
org.label-schema.name="ownCloud Infinite Scale" \
org.label-schema.vendor="ownCloud GmbH" \
org.label-schema.schema-version="1.0"

View File

@@ -7,7 +7,7 @@ RUN apk update && \
echo 'hosts: files dns' >| /etc/nsswitch.conf
LABEL maintainer="ownCloud GmbH <devops@owncloud.com>" \
org.label-schema.name="oCIS" \
org.label-schema.name="ownCloud Infinite Scale" \
org.label-schema.vendor="ownCloud GmbH" \
org.label-schema.schema-version="1.0"

View File

@@ -5,16 +5,16 @@ anchor: "building"
weight: 30
---
As this project is built with Go, so you need to install that first. The installation of Go is out of the scope of this document, please follow the official documentation for [Go](golang), to build this project you have to install Go >= v1.12. After the installation of the required tools you need to get the sources:
As this project is built with Go, so you need to install that first. The installation of Go is out of the scope of this document, please follow the official documentation for [Go](https://golang.org/doc/install), to build this project you have to install Go >= v1.13. After the installation of the required tools you need to get the sources:
{{< highlight txt >}}
git clone https://github.com/owncloud/ocis.git
cd ocis
{{< / highlight >}}
All required tool besides Go itself and make are bundled or getting automatically installed within the `GOPATH`. All commands to build this project are part of our `Makefile` and respectively our `package.json`.
All required tool besides Go itself and make are bundled or getting automatically installed within the `GOPATH`. All commands to build this project are part of our `Makefile`.
## Backend
### Backend
{{< highlight txt >}}
make generate
@@ -22,7 +22,3 @@ make build
{{< / highlight >}}
Finally you should have the binary within the `bin/` folder now, give it a try with `./bin/ocis -h` to see all available options.
[golang]: https://golang.org/doc/install
[nodejs]: https://nodejs.org/en/download/package-manager/
[yarn]: https://yarnpkg.com/lang/en/docs/install/

View File

@@ -7,7 +7,7 @@ weight: 20
## Installation
So far we are offering two different variants for the installation. You can choose between [Docker](docker) or pre-built binaries which are stored on our download mirrors and GitHub releases. Maybe we will also provide system packages for the major distributions later if we see the need for it.
So far we are offering two different variants for the installation. You can choose between [Docker](https://www.docker.com/) or pre-built binaries which are stored on our download mirrors and GitHub releases. Maybe we will also provide system packages for the major distributions later if we see the need for it.
### Docker
@@ -39,7 +39,7 @@ OCIS_LOG_PRETTY
#### Server
OCIS_DEBUG_ADDR
: Address to bind debug server, defaults to `0.0.0.0:8001`
: Address to bind debug server, defaults to `0.0.0.0:9010`
OCIS_DEBUG_TOKEN
: Token to grant metrics access, empty default value
@@ -48,18 +48,21 @@ OCIS_DEBUG_PPROF
: Enable pprof debugging, defaults to `false`
OCIS_HTTP_ADDR
: Address to bind http server, defaults to `0.0.0.0:8000`
: Address to bind http server, defaults to `0.0.0.0:9000`
OCIS_HTTP_ROOT
: Root path for http endpoint, defaults to `/`
OCIS_GRPC_ADDR
: Address to bind grpc server, defaults to `0.0.0.0:9001`
OCIS_SERVICES_ENABLED
: List of enabled services, defaults to `phoenix,ocs,webdav,hello`
: List of enabled services, defaults to `phoenix,konnectd,graph,ocs,webdav,hello`
#### Health
OCIS_DEBUG_ADDR
: Address to debug endpoint, defaults to `0.0.0.0:8001`
: Address to debug endpoint, defaults to `0.0.0.0:9010`
### Commandline flags
@@ -79,7 +82,7 @@ If you prefer to configure the service with commandline flags you can see the av
#### Server
--debug-addr
: Address to bind debug server, defaults to `0.0.0.0:8001`
: Address to bind debug server, defaults to `0.0.0.0:9010`
--debug-token
: Token to grant metrics access, empty default value
@@ -88,22 +91,25 @@ If you prefer to configure the service with commandline flags you can see the av
: Enable pprof debugging, defaults to `false`
--http-addr
: Address to bind http server, defaults to `0.0.0.0:8000`
: Address to bind http server, defaults to `0.0.0.0:9000`
--http-root
: Root path for http endpoint, defaults to `/`
--grpc-addr
: Address to bind grpc server, defaults to `0.0.0.0:9001`
--services-enabled
: List of enabled services, defaults to `phoenix,ocs,webdav,hello`
: List of enabled services, defaults to `phoenix,konnectd,graph,ocs,webdav,hello`
#### Health
--debug-addr
: Address to debug endpoint, defaults to `0.0.0.0:8001`
: Address to debug endpoint, defaults to `0.0.0.0:9010`
### Configuration file
So far we support the file formats `JSON` and `YAML`, if you want to get a full example configuration just take a look at [our repository](repo), there you can always see the latest configuration format. These example configurations include all available options and the default values. The configuration file will be automatically loaded if it's placed at `/etc/ocis/ocis.yml`, `${HOME}/.ocis/ocis.yml` or `$(pwd)/config/ocis.yml`.
So far we support the file formats `JSON` and `YAML`, if you want to get a full example configuration just take a look at [our repository](https://github.com/owncloud/ocis/tree/master/config), there you can always see the latest configuration format. These example configurations include all available options and the default values. The configuration file will be automatically loaded if it's placed at `/etc/ocis/ocis.yml`, `${HOME}/.ocis/ocis.yml` or `$(pwd)/config/ocis.yml`.
## Usage
@@ -127,7 +133,7 @@ ocis health --help
## Metrics
This service provides some [Prometheus](prom) metrics through the debug endpoint, you can optionally secure the metrics endpoint by some random token, which got to be configured through one of the flag `--debug-token` or the environment variable `OCIS_DEBUG_TOKEN` mentioned above. By default the metrics endpoint is bound to `http://0.0.0.0:8001/metrics`.
This service provides some [Prometheus](https://prometheus.io/) metrics through the debug endpoint, you can optionally secure the metrics endpoint by some random token, which got to be configured through one of the flag `--debug-token` or the environment variable `OCIS_DEBUG_TOKEN` mentioned above. By default the metrics endpoint is bound to `http://0.0.0.0:8001/metrics`.
go_gc_duration_seconds
: A summary of the GC invocation durations
@@ -224,7 +230,3 @@ promhttp_metric_handler_requests_in_flight
promhttp_metric_handler_requests_total
: Total number of scrapes by HTTP status code
[docker]: https://www.docker.com/
[repo]: https://github.com/owncloud/ocis/tree/master/config
[prom]: https://prometheus.io/

View File

@@ -5,6 +5,4 @@ anchor: "license"
weight: 40
---
This project is licensed under the [Apache 2.0](license) license. For the license of the used libraries you have to check the respective sources.
[license]: https://github.com/owncloud/ocis/blob/master/LICENSE
This project is licensed under the [Apache 2.0](https://github.com/owncloud/ocis/blob/master/LICENSE) license. For the license of the used libraries you have to check the respective sources.

23
go.mod
View File

@@ -1,12 +1,21 @@
module github.com/owncloud/ocis
go 1.12
go 1.13
require (
github.com/owncloud/ocis-ocs v0.0.0-20190905101159-0d7ed8b013a2
github.com/owncloud/ocis-phoenix v0.0.0-20190905101144-daaf1e6ddb5e
github.com/owncloud/ocis-webdav v0.0.0-20190905101156-4d74712e7d46
github.com/rs/zerolog v1.15.0
github.com/spf13/cobra v0.0.5
github.com/spf13/viper v1.4.0
contrib.go.opencensus.io/exporter/jaeger v0.2.0
contrib.go.opencensus.io/exporter/ocagent v0.6.0
contrib.go.opencensus.io/exporter/zipkin v0.1.1
github.com/micro/cli v0.2.0
github.com/oklog/run v1.0.0
github.com/openzipkin/zipkin-go v0.2.2
github.com/owncloud/ocis-graph v0.0.0-20191210114050-fc7e3d748b12
github.com/owncloud/ocis-hello v0.0.0-20191209151829-dd129732c21d
github.com/owncloud/ocis-konnectd v0.0.0-20191210084549-0f2829ca1bff
github.com/owncloud/ocis-ocs v0.0.0-20191210090203-3f4c51b962f3
github.com/owncloud/ocis-phoenix v0.0.0-20191209152623-c73b270f8783
github.com/owncloud/ocis-pkg v1.2.0
github.com/owncloud/ocis-webdav v0.0.0-20191210090227-af2e98f1e6a9
github.com/spf13/viper v1.6.1
go.opencensus.io v0.22.2
)

878
go.sum

File diff suppressed because it is too large Load Diff

View File

@@ -1,104 +0,0 @@
package command
import (
"os"
"strings"
"github.com/owncloud/ocis/pkg/version"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
// Root is the entry point for the ocis-phoenix command.
func Root() *cobra.Command {
cmd := &cobra.Command{
Use: "ocis",
Short: "ownCloud infinite scale stack",
Long: ``,
Version: version.String,
PersistentPreRun: func(cmd *cobra.Command, args []string) {
setupLogger()
setupConfig()
},
}
cmd.PersistentFlags().String("log-level", "", "Set logging level")
viper.BindPFlag("log.level", cmd.PersistentFlags().Lookup("log-level"))
viper.SetDefault("log.level", "info")
viper.BindEnv("log.level", "HYPER_LOG_LEVEL")
cmd.PersistentFlags().Bool("log-pretty", false, "Enable pretty logging")
viper.BindPFlag("log.pretty", cmd.PersistentFlags().Lookup("log-pretty"))
viper.SetDefault("log.pretty", true)
viper.BindEnv("log.pretty", "HYPER_LOG_PRETTY")
cmd.PersistentFlags().Bool("log-color", false, "Enable colored logging")
viper.BindPFlag("log.color", cmd.PersistentFlags().Lookup("log-color"))
viper.SetDefault("log.color", true)
viper.BindEnv("log.color", "HYPER_LOG_COLOR")
cmd.AddCommand(Phoenix())
cmd.AddCommand(Webdav())
cmd.AddCommand(Ocs())
cmd.AddCommand(Health())
return cmd
}
func setupLogger() {
switch strings.ToLower(viper.GetString("log.level")) {
case "panic":
zerolog.SetGlobalLevel(zerolog.PanicLevel)
case "fatal":
zerolog.SetGlobalLevel(zerolog.FatalLevel)
case "error":
zerolog.SetGlobalLevel(zerolog.ErrorLevel)
case "warn":
zerolog.SetGlobalLevel(zerolog.WarnLevel)
case "info":
zerolog.SetGlobalLevel(zerolog.InfoLevel)
case "debug":
zerolog.SetGlobalLevel(zerolog.DebugLevel)
default:
zerolog.SetGlobalLevel(zerolog.InfoLevel)
}
if viper.GetBool("log.pretty") {
log.Logger = log.Output(
zerolog.ConsoleWriter{
Out: os.Stderr,
NoColor: !viper.GetBool("log.color"),
},
)
}
}
func setupConfig() {
viper.SetConfigName("hyper")
viper.AddConfigPath("/etc/ocis")
viper.AddConfigPath("$HOME/.ocis")
viper.AddConfigPath("./config")
if err := viper.ReadInConfig(); err != nil {
switch err.(type) {
case viper.ConfigFileNotFoundError:
log.Debug().
Msg("Continue without config")
case viper.UnsupportedConfigError:
log.Fatal().
Msg("Unsupported config type")
default:
if e := log.Debug(); e.Enabled() {
log.Fatal().
Err(err).
Msg("Failed to read config")
} else {
log.Fatal().
Msg("Failed to read config")
}
}
}
}

84
pkg/command/graph.go Normal file
View File

@@ -0,0 +1,84 @@
package command
import (
"context"
"github.com/micro/cli"
"github.com/oklog/run"
"github.com/owncloud/ocis-graph/pkg/command"
svcconfig "github.com/owncloud/ocis-graph/pkg/config"
"github.com/owncloud/ocis-graph/pkg/flagset"
"github.com/owncloud/ocis-graph/pkg/metrics"
"github.com/owncloud/ocis-graph/pkg/server/http"
"github.com/owncloud/ocis/pkg/config"
"github.com/owncloud/ocis/pkg/register"
)
// GraphCommand is the entrypoint for the graph command.
func GraphCommand(cfg *config.Config) cli.Command {
return cli.Command{
Name: "graph",
Usage: "Start graph server",
Flags: flagset.ServerWithConfig(cfg.Graph),
Action: func(c *cli.Context) error {
scfg := configureGraph(cfg)
return cli.HandleAction(
command.Server(scfg).Action,
c,
)
},
}
}
// GraphHandler defines the direct server handler.
func GraphHandler(ctx context.Context, cancel context.CancelFunc, gr run.Group, cfg *config.Config) error {
scfg := configureGraph(cfg)
logger := command.NewLogger(scfg)
m := metrics.New()
{
server, err := http.Server(
http.Logger(logger),
http.Context(ctx),
http.Config(scfg),
http.Metrics(m),
)
if err != nil {
logger.Info().
Err(err).
Str("transport", "http").
Msg("Failed to initialize server")
return err
}
gr.Add(func() error {
return server.Run()
}, func(_ error) {
logger.Info().
Str("transport", "http").
Msg("Shutting down server")
cancel()
})
}
return nil
}
func configureGraph(cfg *config.Config) *svcconfig.Config {
cfg.Graph.Log.Level = cfg.Log.Level
cfg.Graph.Log.Pretty = cfg.Log.Pretty
cfg.Graph.Log.Color = cfg.Log.Color
cfg.Graph.Tracing.Enabled = false
cfg.Graph.HTTP.Root = "/"
return cfg.Graph
}
func init() {
register.AddCommand(GraphCommand)
register.AddHandler(GraphHandler)
}

View File

@@ -1,27 +1,49 @@
package command
import (
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"fmt"
"net/http"
"github.com/micro/cli"
"github.com/owncloud/ocis/pkg/config"
"github.com/owncloud/ocis/pkg/flagset"
)
// Health is the entrypoint for the health command.
func Health() *cobra.Command {
cmd := &cobra.Command{
Use: "health",
Short: "Check health status",
Long: "",
Run: func(cmd *cobra.Command, args []string) {
log.Info().
Str("addr", viper.GetString("metrics.addr")).
Msg("Executed health command")
func Health(cfg *config.Config) cli.Command {
return cli.Command{
Name: "health",
Usage: "Check health status",
Flags: flagset.HealthWithConfig(cfg),
Action: func(c *cli.Context) error {
logger := NewLogger(cfg)
resp, err := http.Get(
fmt.Sprintf(
"http://%s/healthz",
cfg.Debug.Addr,
),
)
if err != nil {
logger.Fatal().
Err(err).
Msg("Failed to request health check")
}
defer resp.Body.Close()
if resp.StatusCode != 200 {
logger.Fatal().
Int("code", resp.StatusCode).
Msg("Health seems to be in bad state")
}
logger.Debug().
Int("code", resp.StatusCode).
Msg("Health got a good state")
return nil
},
}
cmd.Flags().String("metrics-addr", "", "Address to metrics endpoint")
viper.BindPFlag("metrics.addr", cmd.Flags().Lookup("metrics-addr"))
viper.BindEnv("metrics.addr", "HYPER_METRICS_ADDR")
return cmd
}

113
pkg/command/hello.go Normal file
View File

@@ -0,0 +1,113 @@
package command
import (
"context"
"github.com/micro/cli"
"github.com/oklog/run"
"github.com/owncloud/ocis-hello/pkg/command"
svcconfig "github.com/owncloud/ocis-hello/pkg/config"
"github.com/owncloud/ocis-hello/pkg/flagset"
"github.com/owncloud/ocis-hello/pkg/metrics"
"github.com/owncloud/ocis-hello/pkg/server/grpc"
"github.com/owncloud/ocis-hello/pkg/server/http"
"github.com/owncloud/ocis/pkg/config"
"github.com/owncloud/ocis/pkg/register"
)
// HelloCommand is the entrypoint for the hello command.
func HelloCommand(cfg *config.Config) cli.Command {
return cli.Command{
Name: "hello",
Usage: "Start hello server",
Flags: flagset.ServerWithConfig(cfg.Hello),
Action: func(c *cli.Context) error {
scfg := configureHello(cfg)
return cli.HandleAction(
command.Server(scfg).Action,
c,
)
},
}
}
// HelloHandler defines the direct server handler.
func HelloHandler(ctx context.Context, cancel context.CancelFunc, gr run.Group, cfg *config.Config) error {
scfg := configureHello(cfg)
logger := command.NewLogger(scfg)
m := metrics.New()
{
server, err := http.Server(
http.Logger(logger),
http.Context(ctx),
http.Config(scfg),
http.Metrics(m),
)
if err != nil {
logger.Info().
Err(err).
Str("transport", "http").
Msg("Failed to initialize server")
return err
}
gr.Add(func() error {
return server.Run()
}, func(_ error) {
logger.Info().
Str("transport", "http").
Msg("Shutting down server")
cancel()
})
}
{
server, err := grpc.Server(
grpc.Logger(logger),
grpc.Context(ctx),
grpc.Config(scfg),
grpc.Metrics(m),
)
if err != nil {
logger.Info().
Err(err).
Str("transport", "grpc").
Msg("Failed to initialize server")
return err
}
gr.Add(func() error {
return server.Run()
}, func(_ error) {
logger.Info().
Str("transport", "grpc").
Msg("Shutting down server")
cancel()
})
}
return nil
}
func configureHello(cfg *config.Config) *svcconfig.Config {
cfg.Hello.Log.Level = cfg.Log.Level
cfg.Hello.Log.Pretty = cfg.Log.Pretty
cfg.Hello.Log.Color = cfg.Log.Color
cfg.Hello.Tracing.Enabled = false
cfg.Hello.HTTP.Root = "/"
return cfg.Hello
}
func init() {
register.AddCommand(HelloCommand)
register.AddHandler(HelloHandler)
}

84
pkg/command/konnectd.go Normal file
View File

@@ -0,0 +1,84 @@
package command
import (
"context"
"github.com/micro/cli"
"github.com/oklog/run"
"github.com/owncloud/ocis-konnectd/pkg/command"
svcconfig "github.com/owncloud/ocis-konnectd/pkg/config"
"github.com/owncloud/ocis-konnectd/pkg/flagset"
"github.com/owncloud/ocis-konnectd/pkg/metrics"
"github.com/owncloud/ocis-konnectd/pkg/server/http"
"github.com/owncloud/ocis/pkg/config"
"github.com/owncloud/ocis/pkg/register"
)
// KonnectdCommand is the entrypoint for the konnectd command.
func KonnectdCommand(cfg *config.Config) cli.Command {
return cli.Command{
Name: "konnectd",
Usage: "Start konnectd server",
Flags: flagset.ServerWithConfig(cfg.Konnectd),
Action: func(c *cli.Context) error {
scfg := configureKonnectd(cfg)
return cli.HandleAction(
command.Server(scfg).Action,
c,
)
},
}
}
// KonnectdHandler defines the direct server handler.
func KonnectdHandler(ctx context.Context, cancel context.CancelFunc, gr run.Group, cfg *config.Config) error {
scfg := configureKonnectd(cfg)
logger := command.NewLogger(scfg)
m := metrics.New()
{
server, err := http.Server(
http.Logger(logger),
http.Context(ctx),
http.Config(scfg),
http.Metrics(m),
)
if err != nil {
logger.Info().
Err(err).
Str("transport", "http").
Msg("Failed to initialize server")
return err
}
gr.Add(func() error {
return server.Run()
}, func(_ error) {
logger.Info().
Str("transport", "http").
Msg("Shutting down server")
cancel()
})
}
return nil
}
func configureKonnectd(cfg *config.Config) *svcconfig.Config {
cfg.Konnectd.Log.Level = cfg.Log.Level
cfg.Konnectd.Log.Pretty = cfg.Log.Pretty
cfg.Konnectd.Log.Color = cfg.Log.Color
cfg.Konnectd.Tracing.Enabled = false
cfg.Konnectd.HTTP.Root = "/"
return cfg.Konnectd
}
func init() {
register.AddCommand(KonnectdCommand)
register.AddHandler(KonnectdHandler)
}

View File

@@ -1,15 +1,84 @@
package command
import (
ocs "github.com/owncloud/ocis-ocs/pkg/command"
"github.com/spf13/cobra"
"context"
"github.com/micro/cli"
"github.com/oklog/run"
"github.com/owncloud/ocis-ocs/pkg/command"
svcconfig "github.com/owncloud/ocis-ocs/pkg/config"
"github.com/owncloud/ocis-ocs/pkg/flagset"
"github.com/owncloud/ocis-ocs/pkg/metrics"
"github.com/owncloud/ocis-ocs/pkg/server/http"
"github.com/owncloud/ocis/pkg/config"
"github.com/owncloud/ocis/pkg/register"
)
// Ocs is the entry point for the ocs command.
func Ocs() *cobra.Command {
cmd := ocs.Server()
cmd.Use = "ocs"
cmd.Short = "Start ocs server"
// OCSCommand is the entrypoint for the ocs command.
func OCSCommand(cfg *config.Config) cli.Command {
return cli.Command{
Name: "ocs",
Usage: "Start ocs server",
Flags: flagset.ServerWithConfig(cfg.OCS),
Action: func(c *cli.Context) error {
scfg := configureOCS(cfg)
return cmd
return cli.HandleAction(
command.Server(scfg).Action,
c,
)
},
}
}
// OCSHandler defines the direct server handler.
func OCSHandler(ctx context.Context, cancel context.CancelFunc, gr run.Group, cfg *config.Config) error {
scfg := configureOCS(cfg)
logger := command.NewLogger(scfg)
m := metrics.New()
{
server, err := http.Server(
http.Logger(logger),
http.Context(ctx),
http.Config(scfg),
http.Metrics(m),
)
if err != nil {
logger.Info().
Err(err).
Str("transport", "http").
Msg("Failed to initialize server")
return err
}
gr.Add(func() error {
return server.Run()
}, func(_ error) {
logger.Info().
Str("transport", "http").
Msg("Shutting down server")
cancel()
})
}
return nil
}
func configureOCS(cfg *config.Config) *svcconfig.Config {
cfg.OCS.Log.Level = cfg.Log.Level
cfg.OCS.Log.Pretty = cfg.Log.Pretty
cfg.OCS.Log.Color = cfg.Log.Color
cfg.OCS.Tracing.Enabled = false
cfg.OCS.HTTP.Root = "/"
return cfg.OCS
}
func init() {
register.AddCommand(OCSCommand)
register.AddHandler(OCSHandler)
}

View File

@@ -1,15 +1,84 @@
package command
import (
phoenix "github.com/owncloud/ocis-phoenix/pkg/command"
"github.com/spf13/cobra"
"context"
"github.com/micro/cli"
"github.com/oklog/run"
"github.com/owncloud/ocis-phoenix/pkg/command"
svcconfig "github.com/owncloud/ocis-phoenix/pkg/config"
"github.com/owncloud/ocis-phoenix/pkg/flagset"
"github.com/owncloud/ocis-phoenix/pkg/metrics"
"github.com/owncloud/ocis-phoenix/pkg/server/http"
"github.com/owncloud/ocis/pkg/config"
"github.com/owncloud/ocis/pkg/register"
)
// Phoenix is the entry point for the phoenix command.
func Phoenix() *cobra.Command {
cmd := phoenix.Server()
cmd.Use = "phoenix"
cmd.Short = "Start phoenix server"
// PhoenixCommand is the entrypoint for the phoenix command.
func PhoenixCommand(cfg *config.Config) cli.Command {
return cli.Command{
Name: "phoenix",
Usage: "Start phoenix server",
Flags: flagset.ServerWithConfig(cfg.Phoenix),
Action: func(c *cli.Context) error {
scfg := configurePhoenix(cfg)
return cmd
return cli.HandleAction(
command.Server(scfg).Action,
c,
)
},
}
}
// PhoenixHandler defines the direct server handler.
func PhoenixHandler(ctx context.Context, cancel context.CancelFunc, gr run.Group, cfg *config.Config) error {
scfg := configurePhoenix(cfg)
logger := command.NewLogger(scfg)
m := metrics.New()
{
server, err := http.Server(
http.Logger(logger),
http.Context(ctx),
http.Config(scfg),
http.Metrics(m),
)
if err != nil {
logger.Info().
Err(err).
Str("transport", "http").
Msg("Failed to initialize server")
return err
}
gr.Add(func() error {
return server.Run()
}, func(_ error) {
logger.Info().
Str("transport", "http").
Msg("Shutting down server")
cancel()
})
}
return nil
}
func configurePhoenix(cfg *config.Config) *svcconfig.Config {
cfg.Phoenix.Log.Level = cfg.Log.Level
cfg.Phoenix.Log.Pretty = cfg.Log.Pretty
cfg.Phoenix.Log.Color = cfg.Log.Color
cfg.Phoenix.Tracing.Enabled = false
cfg.Phoenix.HTTP.Root = "/"
return cfg.Phoenix
}
func init() {
register.AddCommand(PhoenixCommand)
register.AddHandler(PhoenixHandler)
}

111
pkg/command/root.go Normal file
View File

@@ -0,0 +1,111 @@
package command
import (
"os"
"strings"
"github.com/micro/cli"
"github.com/owncloud/ocis-pkg/log"
"github.com/owncloud/ocis/pkg/config"
"github.com/owncloud/ocis/pkg/flagset"
"github.com/owncloud/ocis/pkg/register"
"github.com/owncloud/ocis/pkg/version"
"github.com/spf13/viper"
)
// Execute is the entry point for the ocis-ocis command.
func Execute() error {
cfg := config.New()
app := &cli.App{
Name: "ocis",
Version: version.String,
Usage: "ownCloud Infinite Scale Stack",
Compiled: version.Compiled(),
Authors: []cli.Author{
{
Name: "ownCloud GmbH",
Email: "support@owncloud.com",
},
},
Flags: flagset.RootWithConfig(cfg),
Before: func(c *cli.Context) error {
logger := NewLogger(cfg)
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
viper.SetEnvPrefix("OCIS")
viper.AutomaticEnv()
if c.IsSet("config-file") {
viper.SetConfigFile(c.String("config-file"))
} else {
viper.SetConfigName("ocis")
viper.AddConfigPath("/etc/ocis")
viper.AddConfigPath("$HOME/.ocis")
viper.AddConfigPath("./config")
}
if err := viper.ReadInConfig(); err != nil {
switch err.(type) {
case viper.ConfigFileNotFoundError:
logger.Info().
Msg("Continue without config")
case viper.UnsupportedConfigError:
logger.Fatal().
Err(err).
Msg("Unsupported config type")
default:
logger.Fatal().
Err(err).
Msg("Failed to read config")
}
}
if err := viper.Unmarshal(&cfg); err != nil {
logger.Fatal().
Err(err).
Msg("Failed to parse config")
}
return nil
},
Commands: []cli.Command{
Server(cfg),
Health(cfg),
},
}
for _, fn := range register.Commands {
app.Commands = append(
app.Commands,
fn(cfg),
)
}
cli.HelpFlag = &cli.BoolFlag{
Name: "help,h",
Usage: "Show the help",
}
cli.VersionFlag = &cli.BoolFlag{
Name: "version,v",
Usage: "Print the version",
}
return app.Run(os.Args)
}
// NewLogger initializes a service-specific logger instance.
func NewLogger(cfg *config.Config) log.Logger {
return log.NewLogger(
log.Name("ocis"),
log.Level(cfg.Log.Level),
log.Pretty(cfg.Log.Pretty),
log.Color(cfg.Log.Color),
)
}

153
pkg/command/server.go Normal file
View File

@@ -0,0 +1,153 @@
package command
import (
"context"
"os"
"os/signal"
"strings"
"time"
"contrib.go.opencensus.io/exporter/jaeger"
"contrib.go.opencensus.io/exporter/ocagent"
"contrib.go.opencensus.io/exporter/zipkin"
"github.com/micro/cli"
"github.com/oklog/run"
openzipkin "github.com/openzipkin/zipkin-go"
zipkinhttp "github.com/openzipkin/zipkin-go/reporter/http"
"github.com/owncloud/ocis/pkg/config"
"github.com/owncloud/ocis/pkg/flagset"
"github.com/owncloud/ocis/pkg/register"
"go.opencensus.io/stats/view"
"go.opencensus.io/trace"
)
// Server is the entrypoint for the server command.
func Server(cfg *config.Config) cli.Command {
return cli.Command{
Name: "server",
Usage: "Start fullstack server",
Flags: flagset.ServerWithConfig(cfg),
Before: func(c *cli.Context) error {
if cfg.HTTP.Root != "/" {
cfg.HTTP.Root = strings.TrimSuffix(cfg.HTTP.Root, "/")
}
return nil
},
Action: func(c *cli.Context) error {
logger := NewLogger(cfg)
if cfg.Tracing.Enabled {
switch t := cfg.Tracing.Type; t {
case "agent":
exporter, err := ocagent.NewExporter(
ocagent.WithReconnectionPeriod(5*time.Second),
ocagent.WithAddress(cfg.Tracing.Endpoint),
ocagent.WithServiceName(cfg.Tracing.Service),
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create agent tracing")
return err
}
trace.RegisterExporter(exporter)
view.RegisterExporter(exporter)
case "jaeger":
exporter, err := jaeger.NewExporter(
jaeger.Options{
AgentEndpoint: cfg.Tracing.Endpoint,
CollectorEndpoint: cfg.Tracing.Collector,
ServiceName: cfg.Tracing.Service,
},
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create jaeger tracing")
return err
}
trace.RegisterExporter(exporter)
case "zipkin":
endpoint, err := openzipkin.NewEndpoint(
cfg.Tracing.Service,
cfg.Tracing.Endpoint,
)
if err != nil {
logger.Error().
Err(err).
Str("endpoint", cfg.Tracing.Endpoint).
Str("collector", cfg.Tracing.Collector).
Msg("Failed to create zipkin tracing")
return err
}
exporter := zipkin.NewExporter(
zipkinhttp.NewReporter(
cfg.Tracing.Collector,
),
endpoint,
)
trace.RegisterExporter(exporter)
default:
logger.Warn().
Str("type", t).
Msg("Unknown tracing backend")
}
trace.ApplyConfig(
trace.Config{
DefaultSampler: trace.AlwaysSample(),
},
)
} else {
logger.Debug().
Msg("Tracing is not enabled")
}
var (
gr = run.Group{}
ctx, cancel = context.WithCancel(context.Background())
)
defer cancel()
for _, fn := range register.Handlers {
fn(ctx, cancel, gr, cfg)
}
{
stop := make(chan os.Signal, 1)
gr.Add(func() error {
signal.Notify(stop, os.Interrupt)
<-stop
return nil
}, func(err error) {
close(stop)
cancel()
})
}
return gr.Run()
},
}
}

View File

@@ -1,15 +1,84 @@
package command
import (
webdav "github.com/owncloud/ocis-webdav/pkg/command"
"github.com/spf13/cobra"
"context"
"github.com/micro/cli"
"github.com/oklog/run"
"github.com/owncloud/ocis-webdav/pkg/command"
svcconfig "github.com/owncloud/ocis-webdav/pkg/config"
"github.com/owncloud/ocis-webdav/pkg/flagset"
"github.com/owncloud/ocis-webdav/pkg/metrics"
"github.com/owncloud/ocis-webdav/pkg/server/http"
"github.com/owncloud/ocis/pkg/config"
"github.com/owncloud/ocis/pkg/register"
)
// Webdav is the entry point for the webdav command.
func Webdav() *cobra.Command {
cmd := webdav.Server()
cmd.Use = "webdav"
cmd.Short = "Start webdav server"
// WebDAVCommand is the entrypoint for the webdav command.
func WebDAVCommand(cfg *config.Config) cli.Command {
return cli.Command{
Name: "webdav",
Usage: "Start webdav server",
Flags: flagset.ServerWithConfig(cfg.WebDAV),
Action: func(c *cli.Context) error {
scfg := configureWebDAV(cfg)
return cmd
return cli.HandleAction(
command.Server(scfg).Action,
c,
)
},
}
}
// WebDAVHandler defines the direct server handler.
func WebDAVHandler(ctx context.Context, cancel context.CancelFunc, gr run.Group, cfg *config.Config) error {
scfg := configureWebDAV(cfg)
logger := command.NewLogger(scfg)
m := metrics.New()
{
server, err := http.Server(
http.Logger(logger),
http.Context(ctx),
http.Config(scfg),
http.Metrics(m),
)
if err != nil {
logger.Info().
Err(err).
Str("transport", "http").
Msg("Failed to initialize server")
return err
}
gr.Add(func() error {
return server.Run()
}, func(_ error) {
logger.Info().
Str("transport", "http").
Msg("Shutting down server")
cancel()
})
}
return nil
}
func configureWebDAV(cfg *config.Config) *svcconfig.Config {
cfg.WebDAV.Log.Level = cfg.Log.Level
cfg.WebDAV.Log.Pretty = cfg.Log.Pretty
cfg.WebDAV.Log.Color = cfg.Log.Color
cfg.WebDAV.Tracing.Enabled = false
cfg.WebDAV.HTTP.Root = "/"
return cfg.WebDAV
}
func init() {
register.AddCommand(WebDAVCommand)
register.AddHandler(WebDAVHandler)
}

74
pkg/config/config.go Normal file
View File

@@ -0,0 +1,74 @@
package config
import (
graph "github.com/owncloud/ocis-graph/pkg/config"
hello "github.com/owncloud/ocis-hello/pkg/config"
konnectd "github.com/owncloud/ocis-konnectd/pkg/config"
ocs "github.com/owncloud/ocis-ocs/pkg/config"
phoenix "github.com/owncloud/ocis-phoenix/pkg/config"
webdav "github.com/owncloud/ocis-webdav/pkg/config"
)
// Log defines the available logging configuration.
type Log struct {
Level string
Pretty bool
Color bool
}
// Debug defines the available debug configuration.
type Debug struct {
Addr string
Token string
Pprof bool
Zpages bool
}
// HTTP defines the available http configuration.
type HTTP struct {
Addr string
Root string
}
// GRPC defines the available grpc configuration.
type GRPC struct {
Addr string
}
// Tracing defines the available tracing configuration.
type Tracing struct {
Enabled bool
Type string
Endpoint string
Collector string
Service string
}
// Config combines all available configuration parts.
type Config struct {
File string
Log Log
Debug Debug
HTTP HTTP
GRPC GRPC
Tracing Tracing
Graph *graph.Config
Hello *hello.Config
Konnectd *konnectd.Config
OCS *ocs.Config
Phoenix *phoenix.Config
WebDAV *webdav.Config
}
// New initializes a new configuration with or without defaults.
func New() *Config {
return &Config{
Graph: graph.New(),
Hello: hello.New(),
Konnectd: konnectd.New(),
OCS: ocs.New(),
Phoenix: phoenix.New(),
WebDAV: webdav.New(),
}
}

138
pkg/flagset/flagset.go Normal file
View File

@@ -0,0 +1,138 @@
package flagset
import (
"github.com/micro/cli"
"github.com/owncloud/ocis/pkg/config"
)
// RootWithConfig applies cfg to the root flagset
func RootWithConfig(cfg *config.Config) []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: "config-file",
Value: "",
Usage: "Path to config file",
EnvVar: "OCIS_CONFIG_FILE",
Destination: &cfg.File,
},
&cli.StringFlag{
Name: "log-level",
Value: "info",
Usage: "Set logging level",
EnvVar: "OCIS_LOG_LEVEL",
Destination: &cfg.Log.Level,
},
&cli.BoolTFlag{
Name: "log-pretty",
Usage: "Enable pretty logging",
EnvVar: "OCIS_LOG_PRETTY",
Destination: &cfg.Log.Pretty,
},
&cli.BoolTFlag{
Name: "log-color",
Usage: "Enable colored logging",
EnvVar: "OCIS_LOG_COLOR",
Destination: &cfg.Log.Color,
},
}
}
// HealthWithConfig applies cfg to the root flagset
func HealthWithConfig(cfg *config.Config) []cli.Flag {
return []cli.Flag{
&cli.StringFlag{
Name: "debug-addr",
Value: "0.0.0.0:9010",
Usage: "Address to debug endpoint",
EnvVar: "OCIS_DEBUG_ADDR",
Destination: &cfg.Debug.Addr,
},
}
}
// ServerWithConfig applies cfg to the root flagset
func ServerWithConfig(cfg *config.Config) []cli.Flag {
return []cli.Flag{
&cli.BoolFlag{
Name: "tracing-enabled",
Usage: "Enable sending traces",
EnvVar: "OCIS_TRACING_ENABLED",
Destination: &cfg.Tracing.Enabled,
},
&cli.StringFlag{
Name: "tracing-type",
Value: "jaeger",
Usage: "Tracing backend type",
EnvVar: "OCIS_TRACING_TYPE",
Destination: &cfg.Tracing.Type,
},
&cli.StringFlag{
Name: "tracing-endpoint",
Value: "",
Usage: "Endpoint for the agent",
EnvVar: "OCIS_TRACING_ENDPOINT",
Destination: &cfg.Tracing.Endpoint,
},
&cli.StringFlag{
Name: "tracing-collector",
Value: "",
Usage: "Endpoint for the collector",
EnvVar: "OCIS_TRACING_COLLECTOR",
Destination: &cfg.Tracing.Collector,
},
&cli.StringFlag{
Name: "tracing-service",
Value: "hello",
Usage: "Service name for tracing",
EnvVar: "OCIS_TRACING_SERVICE",
Destination: &cfg.Tracing.Service,
},
&cli.StringFlag{
Name: "debug-addr",
Value: "0.0.0.0:9010",
Usage: "Address to bind debug server",
EnvVar: "OCIS_DEBUG_ADDR",
Destination: &cfg.Debug.Addr,
},
&cli.StringFlag{
Name: "debug-token",
Value: "",
Usage: "Token to grant metrics access",
EnvVar: "OCIS_DEBUG_TOKEN",
Destination: &cfg.Debug.Token,
},
&cli.BoolFlag{
Name: "debug-pprof",
Usage: "Enable pprof debugging",
EnvVar: "OCIS_DEBUG_PPROF",
Destination: &cfg.Debug.Pprof,
},
&cli.BoolFlag{
Name: "debug-zpages",
Usage: "Enable zpages debugging",
EnvVar: "OCIS_DEBUG_ZPAGES",
Destination: &cfg.Debug.Zpages,
},
&cli.StringFlag{
Name: "http-addr",
Value: "0.0.0.0:9000",
Usage: "Address to bind http server",
EnvVar: "OCIS_HTTP_ADDR",
Destination: &cfg.HTTP.Addr,
},
&cli.StringFlag{
Name: "http-root",
Value: "/",
Usage: "Root path of http server",
EnvVar: "OCIS_HTTP_ROOT",
Destination: &cfg.HTTP.Root,
},
&cli.StringFlag{
Name: "grpc-addr",
Value: "0.0.0.0:9001",
Usage: "Address to bind grpc server",
EnvVar: "OCIS_GRPC_ADDR",
Destination: &cfg.GRPC.Addr,
},
}
}

39
pkg/register/command.go Normal file
View File

@@ -0,0 +1,39 @@
package register
import (
"context"
"github.com/micro/cli"
"github.com/oklog/run"
"github.com/owncloud/ocis/pkg/config"
)
var (
// Commands defines the slice of commands.
Commands = []Command{}
// Handlers defines the slice of handlers.
Handlers = []Handler{}
)
// Command defines the register command.
type Command func(*config.Config) cli.Command
// Handler defines the register handler.
type Handler func(context.Context, context.CancelFunc, run.Group, *config.Config) error
// AddCommand appends a command to Commands.
func AddCommand(cmd Command) {
Commands = append(
Commands,
cmd,
)
}
// AddHandler appends a handler to Handlers.
func AddHandler(hdl Handler) {
Handlers = append(
Handlers,
hdl,
)
}

View File

@@ -1,5 +1,9 @@
package version
import (
"time"
)
var (
// String gets defined by the build system.
String = "0.0.0"
@@ -7,3 +11,9 @@ var (
// Date indicates the build date.
Date = "00000000"
)
// Compiled returns the compile time of this service.
func Compiled() time.Time {
t, _ := time.Parse("20060102", Date)
return t
}

2
reflex.conf Normal file
View File

@@ -0,0 +1,2 @@
# backend
-r '^(cmd|pkg)/.*\.go$' -R '^node_modules/' -s -- sh -c 'make bin/ocis-debug && bin/ocis-debug --log-level debug server --debug-pprof --debug-zpages'