2020-01-13 21:05:38 +13:00
|
|
|
package config
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
"github.com/spf13/viper"
|
|
|
|
)
|
|
|
|
|
2020-01-19 12:30:09 +13:00
|
|
|
type Server struct {
|
|
|
|
Cert string
|
|
|
|
Key string
|
|
|
|
Bind string
|
2020-01-13 21:05:38 +13:00
|
|
|
Static string
|
|
|
|
}
|
|
|
|
|
2020-01-19 12:30:09 +13:00
|
|
|
func (Server) Init(cmd *cobra.Command) error {
|
2020-01-13 21:05:38 +13:00
|
|
|
cmd.PersistentFlags().String("bind", "127.0.0.1:8080", "Address/port/socket to serve neko")
|
|
|
|
if err := viper.BindPFlag("bind", cmd.PersistentFlags().Lookup("bind")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.PersistentFlags().String("cert", "", "Path to the SSL cert used to secure the neko server")
|
|
|
|
if err := viper.BindPFlag("cert", cmd.PersistentFlags().Lookup("cert")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
cmd.PersistentFlags().String("key", "", "Path to the SSL key used to secure the neko server")
|
|
|
|
if err := viper.BindPFlag("key", cmd.PersistentFlags().Lookup("key")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
2020-01-19 12:30:09 +13:00
|
|
|
cmd.PersistentFlags().String("static", "./www", "Neko client files to serve")
|
2020-01-13 21:05:38 +13:00
|
|
|
if err := viper.BindPFlag("static", cmd.PersistentFlags().Lookup("static")); err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
2020-01-19 12:30:09 +13:00
|
|
|
func (s *Server) Set() {
|
2020-01-13 21:05:38 +13:00
|
|
|
s.Cert = viper.GetString("cert")
|
|
|
|
s.Key = viper.GetString("key")
|
|
|
|
s.Bind = viper.GetString("bind")
|
|
|
|
s.Static = viper.GetString("static")
|
|
|
|
}
|