make it conf via arg or env

This commit is contained in:
6543 2022-07-24 17:52:07 +02:00
parent aa83b307db
commit b1b23ce2ec
No known key found for this signature in database
GPG key ID: C99B82E40B027BAE
5 changed files with 17 additions and 5 deletions

View file

@ -69,6 +69,17 @@ var ServeFlags = []cli.Flag{
// TODO: desc // TODO: desc
EnvVars: []string{"ENABLE_HTTP_SERVER"}, EnvVars: []string{"ENABLE_HTTP_SERVER"},
}, },
// Server Options
&cli.BoolFlag{
Name: "enable-lfs-support",
Usage: "enable lfs support, require gitea v1.17.0 as backend",
EnvVars: []string{"ENABLE_LFS_SUPPORT"},
},
&cli.BoolFlag{
Name: "enable-symlink-support",
Usage: "follow symlinks if enabled, require gitea v1.18.0 as backend",
EnvVars: []string{"ENABLE_SYMLINK_SUPPORT"},
},
// ACME // ACME
&cli.StringFlag{ &cli.StringFlag{

View file

@ -82,7 +82,7 @@ func Serve(ctx *cli.Context) error {
// TODO: make this an MRU cache with a size limit // TODO: make this an MRU cache with a size limit
fileResponseCache := cache.NewKeyValueCache() fileResponseCache := cache.NewKeyValueCache()
giteaClient, err := gitea.NewClient(giteaRoot, giteaAPIToken) giteaClient, err := gitea.NewClient(giteaRoot, giteaAPIToken, ctx.Bool("enable-symlink-support"), ctx.Bool("enable-lfs-support"))
if err != nil { if err != nil {
return fmt.Errorf("could not create new gitea client: %v", err) return fmt.Errorf("could not create new gitea client: %v", err)
} }

View file

@ -9,6 +9,7 @@ import (
"io" "io"
"net/http" "net/http"
"net/http/cookiejar" "net/http/cookiejar"
"strings"
"testing" "testing"
"github.com/rs/zerolog/log" "github.com/rs/zerolog/log"

View file

@ -44,7 +44,7 @@ func joinURL(baseURL string, paths ...string) string {
return baseURL + "/" + strings.Join(p, "/") return baseURL + "/" + strings.Join(p, "/")
} }
func NewClient(giteaRoot, giteaAPIToken string) (*Client, error) { func NewClient(giteaRoot, giteaAPIToken string, followSymlinks, supportLFS bool) (*Client, error) {
rootURL, err := url.Parse(giteaRoot) rootURL, err := url.Parse(giteaRoot)
giteaRoot = strings.Trim(rootURL.String(), "/") giteaRoot = strings.Trim(rootURL.String(), "/")
@ -55,8 +55,8 @@ func NewClient(giteaRoot, giteaAPIToken string) (*Client, error) {
contentTimeout: 10 * time.Second, contentTimeout: 10 * time.Second,
fastClient: getFastHTTPClient(), fastClient: getFastHTTPClient(),
followSymlinks: true, followSymlinks: followSymlinks,
supportLFS: true, supportLFS: supportLFS,
}, err }, err
} }

View file

@ -13,7 +13,7 @@ import (
func TestHandlerPerformance(t *testing.T) { func TestHandlerPerformance(t *testing.T) {
giteaRoot := "https://codeberg.org" giteaRoot := "https://codeberg.org"
giteaClient, _ := gitea.NewClient(giteaRoot, "") giteaClient, _ := gitea.NewClient(giteaRoot, "", false, false)
testHandler := Handler( testHandler := Handler(
[]byte("codeberg.page"), []byte("raw.codeberg.org"), []byte("codeberg.page"), []byte("raw.codeberg.org"),
giteaClient, giteaClient,