resolve linter issues
This commit is contained in:
@@ -1506,6 +1506,7 @@ github.com/spf13/cobra v0.0.6/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHN
|
|||||||
github.com/spf13/cobra v0.0.7/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE=
|
github.com/spf13/cobra v0.0.7/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE=
|
||||||
github.com/spf13/cobra v1.0.0 h1:6m/oheQuQ13N9ks4hubMG6BnvwOeaJrqSPLahSnczz8=
|
github.com/spf13/cobra v1.0.0 h1:6m/oheQuQ13N9ks4hubMG6BnvwOeaJrqSPLahSnczz8=
|
||||||
github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE=
|
github.com/spf13/cobra v1.0.0/go.mod h1:/6GTrnGXV9HjY+aR4k0oJ5tcvakLuG6EuKReYlHNrgE=
|
||||||
|
github.com/spf13/cobra v1.1.3 h1:xghbfqPkxzxP3C/f3n5DdpAbdKLj4ZE4BWQI362l53M=
|
||||||
github.com/spf13/cobra v1.1.3/go.mod h1:pGADOWyqRD/YMrPZigI/zbliZ2wVD/23d+is3pSWzOo=
|
github.com/spf13/cobra v1.1.3/go.mod h1:pGADOWyqRD/YMrPZigI/zbliZ2wVD/23d+is3pSWzOo=
|
||||||
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
|
github.com/spf13/jwalterweatherman v1.0.0/go.mod h1:cQK4TGJAtQXfYWX+Ddv3mKDzgVb68N+wFjFa4jdeBTo=
|
||||||
github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk=
|
github.com/spf13/jwalterweatherman v1.1.0 h1:ue6voC5bR5F8YxI5S67j9i582FU4Qvo2bmqnqMYADFk=
|
||||||
|
|||||||
@@ -19,8 +19,12 @@ func RootCmd(cfg *config.Config) *cobra.Command {
|
|||||||
rootCmd.PersistentFlags().StringVarP(&cfg.Port, "port", "p", "10666", "port to send messages to the rpc oCIS runtime.")
|
rootCmd.PersistentFlags().StringVarP(&cfg.Port, "port", "p", "10666", "port to send messages to the rpc oCIS runtime.")
|
||||||
rootCmd.PersistentFlags().BoolVarP(&cfg.KeepAlive, "keep-alive", "k", false, "restart supervised processes that abruptly die.")
|
rootCmd.PersistentFlags().BoolVarP(&cfg.KeepAlive, "keep-alive", "k", false, "restart supervised processes that abruptly die.")
|
||||||
|
|
||||||
viper.BindPFlag("hostname", rootCmd.PersistentFlags().Lookup("hostname"))
|
if err := viper.BindPFlag("hostname", rootCmd.PersistentFlags().Lookup("hostname")); err != nil {
|
||||||
viper.BindPFlag("port", rootCmd.PersistentFlags().Lookup("port"))
|
panic(err)
|
||||||
|
}
|
||||||
|
if err := viper.BindPFlag("port", rootCmd.PersistentFlags().Lookup("port")); err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
|
||||||
rootCmd.AddCommand(List(cfg))
|
rootCmd.AddCommand(List(cfg))
|
||||||
rootCmd.AddCommand(Run(cfg))
|
rootCmd.AddCommand(Run(cfg))
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ func (j *janitor) cleanup() {
|
|||||||
// On unix like systems (linux, freebsd, etc) os.FindProcess will never return an error
|
// On unix like systems (linux, freebsd, etc) os.FindProcess will never return an error
|
||||||
if p, err := os.FindProcess(pid); err == nil {
|
if p, err := os.FindProcess(pid); err == nil {
|
||||||
if err := p.Signal(syscall.Signal(0)); err != nil {
|
if err := p.Signal(syscall.Signal(0)); err != nil {
|
||||||
j.store.Delete(process.ProcEntry{
|
_ = j.store.Delete(process.ProcEntry{
|
||||||
Pid: pid,
|
Pid: pid,
|
||||||
Extension: name,
|
Extension: name,
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -34,12 +34,16 @@ type Service struct {
|
|||||||
|
|
||||||
// loadFromEnv would set cmd global variables. This is a workaround spf13/viper since pman used as a library does not
|
// loadFromEnv would set cmd global variables. This is a workaround spf13/viper since pman used as a library does not
|
||||||
// parse flags.
|
// parse flags.
|
||||||
func loadFromEnv() *config.Config {
|
func loadFromEnv() (*config.Config, error) {
|
||||||
cfg := config.NewConfig()
|
cfg := config.NewConfig()
|
||||||
viper.AutomaticEnv()
|
viper.AutomaticEnv()
|
||||||
|
|
||||||
viper.BindEnv("keep-alive", "RUNTIME_KEEP_ALIVE")
|
if err := viper.BindEnv("keep-alive", "RUNTIME_KEEP_ALIVE"); err != nil {
|
||||||
viper.BindEnv("port", "RUNTIME_PORT")
|
return nil, err
|
||||||
|
}
|
||||||
|
if err := viper.BindEnv("port", "RUNTIME_PORT"); err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
|
|
||||||
cfg.KeepAlive = viper.GetBool("keep-alive")
|
cfg.KeepAlive = viper.GetBool("keep-alive")
|
||||||
|
|
||||||
@@ -47,7 +51,7 @@ func loadFromEnv() *config.Config {
|
|||||||
cfg.Port = viper.GetString("port")
|
cfg.Port = viper.GetString("port")
|
||||||
}
|
}
|
||||||
|
|
||||||
return cfg
|
return cfg, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewService returns a configured service with a controller and a default logger.
|
// NewService returns a configured service with a controller and a default logger.
|
||||||
@@ -55,14 +59,17 @@ func loadFromEnv() *config.Config {
|
|||||||
// calls are done explicitly to loadFromEnv().
|
// calls are done explicitly to loadFromEnv().
|
||||||
// Since this is the public constructor, options need to be added, at the moment only logging options
|
// Since this is the public constructor, options need to be added, at the moment only logging options
|
||||||
// are supported in order to match the running OwnCloud services structured log.
|
// are supported in order to match the running OwnCloud services structured log.
|
||||||
func NewService(options ...Option) *Service {
|
func NewService(options ...Option) (*Service, error) {
|
||||||
opts := NewOptions()
|
opts := NewOptions()
|
||||||
|
|
||||||
for _, f := range options {
|
for _, f := range options {
|
||||||
f(opts)
|
f(opts)
|
||||||
}
|
}
|
||||||
|
|
||||||
cfg := loadFromEnv()
|
cfg, err := loadFromEnv()
|
||||||
|
if err != nil {
|
||||||
|
return nil, err
|
||||||
|
}
|
||||||
l := log.NewLogger(
|
l := log.NewLogger(
|
||||||
log.WithPretty(opts.Log.Pretty),
|
log.WithPretty(opts.Log.Pretty),
|
||||||
)
|
)
|
||||||
@@ -74,12 +81,15 @@ func NewService(options ...Option) *Service {
|
|||||||
controller.WithConfig(cfg),
|
controller.WithConfig(cfg),
|
||||||
controller.WithLog(&l),
|
controller.WithLog(&l),
|
||||||
),
|
),
|
||||||
}
|
}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// Start an rpc service.
|
// Start an rpc service.
|
||||||
func Start(o ...Option) error {
|
func Start(o ...Option) error {
|
||||||
s := NewService(o...)
|
s, err := NewService(o...)
|
||||||
|
if err != nil {
|
||||||
|
s.Log.Fatal().Err(err)
|
||||||
|
}
|
||||||
|
|
||||||
if err := rpc.Register(s); err != nil {
|
if err := rpc.Register(s); err != nil {
|
||||||
s.Log.Fatal().Err(err)
|
s.Log.Fatal().Err(err)
|
||||||
|
|||||||
@@ -12,7 +12,9 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func TestMain(m *testing.M) {
|
func TestMain(m *testing.M) {
|
||||||
loadStore()
|
if err := loadStore(); err != nil {
|
||||||
|
os.Exit(1)
|
||||||
|
}
|
||||||
os.Exit(m.Run())
|
os.Exit(m.Run())
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -20,13 +22,17 @@ var (
|
|||||||
store = NewMapStorage()
|
store = NewMapStorage()
|
||||||
)
|
)
|
||||||
|
|
||||||
func loadStore() {
|
func loadStore() error {
|
||||||
for i := 0; i < 20; i++ {
|
for i := 0; i < 20; i++ {
|
||||||
store.Store(process.ProcEntry{
|
if err := store.Store(process.ProcEntry{
|
||||||
Pid: rand.Int(),
|
Pid: rand.Int(), //nolint:gosec
|
||||||
Extension: fmt.Sprintf("extension-%s", strconv.Itoa(i)),
|
Extension: fmt.Sprintf("extension-%s", strconv.Itoa(i)),
|
||||||
})
|
}); err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestLoadAll(t *testing.T) {
|
func TestLoadAll(t *testing.T) {
|
||||||
@@ -35,9 +41,10 @@ func TestLoadAll(t *testing.T) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func TestDelete(t *testing.T) {
|
func TestDelete(t *testing.T) {
|
||||||
store.Delete(process.ProcEntry{
|
err := store.Delete(process.ProcEntry{
|
||||||
Extension: "extension-1",
|
Extension: "extension-1",
|
||||||
})
|
})
|
||||||
|
assert.Nil(t, err)
|
||||||
all := store.LoadAll()
|
all := store.LoadAll()
|
||||||
assert.Zero(t, all["extension-1"])
|
assert.Zero(t, all["extension-1"])
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user