Skip to content
This repository has been archived by the owner on Sep 28, 2024. It is now read-only.

Commit

Permalink
use cobra RunE to simplfy the cmds
Browse files Browse the repository at this point in the history
  • Loading branch information
robbyt committed Apr 18, 2024
1 parent 419acdd commit 2b8357a
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 18 deletions.
8 changes: 2 additions & 6 deletions cmd/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ Copyright © 2024 NAME HERE <EMAIL ADDRESS>
package cmd

import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"

"github.com/robbyt/llm_proxy/config"
Expand All @@ -21,12 +20,9 @@ and retrieve the responses. This mode is useful for development and for CI, beca
number of requests to the upstream server. The cache server will respond with the same status code,
headers, and body as the previous response. The cache server will not store responses with a status
code of 500 or higher.`,
Run: func(cmd *cobra.Command, args []string) {
RunE: func(cmd *cobra.Command, args []string) error {
cfg.AppMode = config.CacheMode
err := proxy.Run(cfg)
if err != nil {
log.Fatal(err)
}
return proxy.Run(cfg)
},
}

Expand Down
1 change: 1 addition & 0 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import "github.com/robbyt/llm_proxy/config"
// cfg is a reasonable default configuration, used by all commands
var cfg *config.Config = config.NewDefaultConfig()

// suggestions are here instead of their respective files bc it's easier to see them all in one place
var cache_suggestions = []string{
"cache-proxy", "caching-proxy", "cash-proxy", "cash",
}
Expand Down
8 changes: 2 additions & 6 deletions cmd/dir_logger.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"

"github.com/robbyt/llm_proxy/config"
Expand All @@ -16,12 +15,9 @@ var dirLoggerCmd = &cobra.Command{
Each request/response pair will be written to a file, identified by a unique ID. The file
will contain the request and response in JSON format.
`,
Run: func(cmd *cobra.Command, args []string) {
RunE: func(cmd *cobra.Command, args []string) error {
cfg.AppMode = config.DirLoggerMode
err := proxy.Run(cfg)
if err != nil {
log.Fatal(err)
}
return proxy.Run(cfg)
},
}

Expand Down
8 changes: 2 additions & 6 deletions cmd/simple.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package cmd

import (
log "github.com/sirupsen/logrus"
"github.com/spf13/cobra"

"github.com/robbyt/llm_proxy/config"
Expand All @@ -13,12 +12,9 @@ var simpleCmd = &cobra.Command{
Use: "simple",
Short: "Run a 'simple' proxy server, traffic will not be stored or cached.",
Long: "Useful as a simple proxy to test connectivity, or as a base for a more complex proxy.",
Run: func(cmd *cobra.Command, args []string) {
RunE: func(cmd *cobra.Command, args []string) error {
cfg.AppMode = config.SimpleMode
err := proxy.Run(cfg)
if err != nil {
log.Fatal(err)
}
return proxy.Run(cfg)
},
}

Expand Down

0 comments on commit 2b8357a

Please sign in to comment.