disable legacy mode if wanted.

This commit is contained in:
Miroslav Šedivý 2024-09-07 20:51:21 +02:00
parent db297d246d
commit b3b31fba1f
3 changed files with 40 additions and 25 deletions

View file

@ -7,6 +7,7 @@ import (
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/spf13/cobra"
"github.com/spf13/viper"
"m1k1o/neko/internal/api"
"m1k1o/neko/internal/capture"
@ -88,24 +89,25 @@ func (c *serve) Init(cmd *cobra.Command) error {
}
// V2 configuration
if err := c.configs.Desktop.InitV2(cmd); err != nil {
return err
}
if err := c.configs.Capture.InitV2(cmd); err != nil {
return err
}
if err := c.configs.WebRTC.InitV2(cmd); err != nil {
return err
}
if err := c.configs.Member.InitV2(cmd); err != nil {
return err
}
if err := c.configs.Session.InitV2(cmd); err != nil {
return err
}
if err := c.configs.Server.InitV2(cmd); err != nil {
return err
if viper.GetBool("legacy") {
if err := c.configs.Desktop.InitV2(cmd); err != nil {
return err
}
if err := c.configs.Capture.InitV2(cmd); err != nil {
return err
}
if err := c.configs.WebRTC.InitV2(cmd); err != nil {
return err
}
if err := c.configs.Member.InitV2(cmd); err != nil {
return err
}
if err := c.configs.Session.InitV2(cmd); err != nil {
return err
}
if err := c.configs.Server.InitV2(cmd); err != nil {
return err
}
}
return nil
@ -122,12 +124,14 @@ func (c *serve) PreRun(cmd *cobra.Command, args []string) {
c.configs.Plugins.Set()
c.configs.Server.Set()
c.configs.Desktop.SetV2()
c.configs.Capture.SetV2()
c.configs.WebRTC.SetV2()
c.configs.Member.SetV2()
c.configs.Session.SetV2()
c.configs.Server.SetV2()
if viper.GetBool("legacy") {
c.configs.Desktop.SetV2()
c.configs.Capture.SetV2()
c.configs.WebRTC.SetV2()
c.configs.Member.SetV2()
c.configs.Session.SetV2()
c.configs.Server.SetV2()
}
}
func (c *serve) Start(cmd *cobra.Command) {

View file

@ -13,6 +13,7 @@ import (
type Root struct {
Config string
Legacy bool
LogLevel zerolog.Level
LogTime string
@ -33,6 +34,12 @@ func (Root) Init(cmd *cobra.Command) error {
return err
}
// whether legacy configs/api should be enabled (default: true, until v3.1)
cmd.PersistentFlags().BoolP("legacy", "l", true, "enable legacy mode")
if err := viper.BindPFlag("legacy", cmd.PersistentFlags().Lookup("legacy")); err != nil {
return err
}
cmd.PersistentFlags().String("log.level", "info", "set log level (trace, debug, info, warn, error, fatal, panic, disabled)")
if err := viper.BindPFlag("log.level", cmd.PersistentFlags().Lookup("log.level")); err != nil {
return err
@ -72,6 +79,7 @@ func (Root) InitV2(cmd *cobra.Command) error {
func (s *Root) Set() {
s.Config = viper.GetString("config")
s.Legacy = viper.GetBool("legacy")
logLevel := viper.GetString("log.level")
level, err := zerolog.ParseLevel(logLevel)

View file

@ -8,6 +8,7 @@ import (
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/rs/zerolog"
"github.com/rs/zerolog/log"
"github.com/spf13/viper"
"m1k1o/neko/internal/config"
"m1k1o/neko/internal/http/legacy"
@ -56,7 +57,9 @@ func New(WebSocketManager types.WebSocketManager, ApiManager types.ApiManager, c
}))
// Legacy handler
legacy.New().Route(router)
if viper.GetBool("legacy") {
legacy.New().Route(router)
}
batch := batchHandler{
Router: router,