Skip to content

Commit

Permalink
refactor: remove prefix from common pkgs
Browse files Browse the repository at this point in the history
  • Loading branch information
pyadav committed Jan 31, 2024
1 parent a46e6eb commit f0ec9d3
Show file tree
Hide file tree
Showing 8 changed files with 30 additions and 30 deletions.
10 changes: 5 additions & 5 deletions common/cmd/cmd.go → common/cmdx/cmdx.go
@@ -1,4 +1,4 @@
package mscmd
package cmdx

import (
"errors"
Expand All @@ -7,7 +7,7 @@ import (
"runtime"

"github.com/mcuadros/go-defaults"
msconfig "github.com/missingstudio/studio/common/config"
"github.com/missingstudio/studio/common/config"
"github.com/spf13/pflag"
"gopkg.in/yaml.v2"
)
Expand Down Expand Up @@ -84,13 +84,13 @@ func (c *Config) Load(cfg interface{}, opts ...ConfigLoaderOpt) error {
opt(c)
}

loaderOpts := []msconfig.LoaderOption{msconfig.WithFile(c.filename)}
loaderOpts := []config.LoaderOption{config.WithFile(c.filename)}

if c.boundedPFlags != nil {
loaderOpts = append(loaderOpts, msconfig.WithBindPFlags(c.boundedPFlags, cfg))
loaderOpts = append(loaderOpts, config.WithBindPFlags(c.boundedPFlags, cfg))
}

loader := msconfig.NewLoader(loaderOpts...)
loader := config.NewLoader(loaderOpts...)

if err := loader.Load(cfg); err != nil {
return err
Expand Down
2 changes: 1 addition & 1 deletion common/config/config.go
@@ -1,4 +1,4 @@
package msconfig
package config

import (
"encoding/json"
Expand Down
2 changes: 1 addition & 1 deletion common/errors/errors.go
@@ -1,4 +1,4 @@
package mserrors
package errors

import (
"errors"
Expand Down
2 changes: 1 addition & 1 deletion common/logger/logger.go
@@ -1,4 +1,4 @@
package mslogger
package logger

import (
"log/slog"
Expand Down
8 changes: 4 additions & 4 deletions mobius/cmd/config.go
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"

"github.com/MakeNowJust/heredoc"
mscmd "github.com/missingstudio/studio/common/cmd"
"github.com/missingstudio/studio/common/cmdx"

"github.com/spf13/cobra"
)
Expand All @@ -16,7 +16,7 @@ type Config struct {
func LoadConfig() (*Config, error) {
var config Config

cfg := mscmd.SetConfig("mobius")
cfg := cmdx.SetConfig("mobius")
err := cfg.Load(&config)

return &config, err
Expand Down Expand Up @@ -48,7 +48,7 @@ func configInitCommand() *cobra.Command {
"group": "core",
},
RunE: func(cmd *cobra.Command, args []string) error {
cfg := mscmd.SetConfig("mobius")
cfg := cmdx.SetConfig("mobius")

if err := cfg.Init(&Config{}); err != nil {
return err
Expand All @@ -71,7 +71,7 @@ func configListCommand() *cobra.Command {
"group": "core",
},
RunE: func(cmd *cobra.Command, args []string) error {
cfg := mscmd.SetConfig("mobius")
cfg := cmdx.SetConfig("mobius")

data, err := cfg.Read()
if err != nil {
Expand Down
4 changes: 2 additions & 2 deletions mobius/cmd/server.go
Expand Up @@ -9,7 +9,7 @@ import (
"github.com/MakeNowJust/heredoc"
"github.com/missingstudio/studio/backend/config"
"github.com/missingstudio/studio/backend/pkg/server"
mslogger "github.com/missingstudio/studio/common/logger"
"github.com/missingstudio/studio/common/logger"

"github.com/spf13/cobra"
)
Expand Down Expand Up @@ -67,7 +67,7 @@ func serverStartCommand() *cobra.Command {
panic(err)
}

logger := mslogger.New(appConfig.LogFormatJson, nil)
logger := logger.New(appConfig.LogFormatJson, nil)

ctx, cancelFunc := signal.NotifyContext(context.Background(), syscall.SIGTERM, syscall.SIGINT)
defer cancelFunc()
Expand Down
24 changes: 12 additions & 12 deletions mobius/config/config.go
Expand Up @@ -5,7 +5,7 @@ import (
"os"
"path/filepath"

msconfig "github.com/missingstudio/studio/common/config"
"github.com/missingstudio/studio/common/config"
)

type Config struct {
Expand All @@ -16,29 +16,29 @@ type Config struct {
func Load(serverConfigFileFromFlag string) (*Config, error) {
conf := &Config{}

var options []msconfig.LoaderOption
options = append(options, msconfig.WithName("config"))
options = append(options, msconfig.WithEnvKeyReplacer(".", "_"))
options = append(options, msconfig.WithEnvPrefix("MOBIUS"))
var options []config.LoaderOption
options = append(options, config.WithName("config"))
options = append(options, config.WithEnvKeyReplacer(".", "_"))
options = append(options, config.WithEnvPrefix("MOBIUS"))
if p, err := os.Getwd(); err == nil {
options = append(options, msconfig.WithPath(p))
options = append(options, config.WithPath(p))
}
if execPath, err := os.Executable(); err == nil {
options = append(options, msconfig.WithPath(filepath.Dir(execPath)))
options = append(options, config.WithPath(filepath.Dir(execPath)))
}
if currentHomeDir, err := os.UserHomeDir(); err == nil {
options = append(options, msconfig.WithPath(currentHomeDir))
options = append(options, msconfig.WithPath(filepath.Join(currentHomeDir, ".config")))
options = append(options, config.WithPath(currentHomeDir))
options = append(options, config.WithPath(filepath.Join(currentHomeDir, ".config")))
}

// override all config sources and prioritize one from file
if serverConfigFileFromFlag != "" {
options = append(options, msconfig.WithFile(serverConfigFileFromFlag))
options = append(options, config.WithFile(serverConfigFileFromFlag))
}

l := msconfig.NewLoader(options...)
l := config.NewLoader(options...)
if err := l.Load(conf); err != nil {
if !errors.As(err, &msconfig.ConfigFileNotFoundError{}) {
if !errors.As(err, &config.ConfigFileNotFoundError{}) {
return nil, err
}
}
Expand Down
8 changes: 4 additions & 4 deletions mobius/internal/api/v1/chatcompletions.go
Expand Up @@ -6,7 +6,7 @@ import (
"connectrpc.com/connect"
"github.com/missingstudio/studio/backend/internal/providers"
"github.com/missingstudio/studio/backend/internal/providers/base"
mserrors "github.com/missingstudio/studio/common/errors"
"github.com/missingstudio/studio/common/errors"
llmv1 "github.com/missingstudio/studio/protos/pkg/llm"
)

Expand All @@ -16,17 +16,17 @@ func (s *V1Handler) ChatCompletions(
) (*connect.Response[llmv1.CompletionResponse], error) {
provider, err := providers.GetProvider(ctx)
if err != nil {
return nil, mserrors.NewNotFound("provider not found")
return nil, errors.NewNotFound("provider not found")
}

completionProvider, ok := provider.(base.ChatCompilationInterface)
if !ok {
return nil, mserrors.NewInternalError("not able to get chat compilation provider")
return nil, errors.NewInternalError("not able to get chat compilation provider")
}

data, err := completionProvider.ChatCompilation(ctx, req.Msg)
if err != nil {
return nil, mserrors.New(err)
return nil, errors.New(err)
}

return connect.NewResponse(data), nil
Expand Down

0 comments on commit f0ec9d3

Please sign in to comment.