mirror of
https://github.com/filebrowser/filebrowser.git
synced 2024-06-07 23:00:43 +00:00
chore: style and gofmt (#622)
Former-commit-id: 669963fd1d51d7e2d32520ffb0c1ecd5e4224c78 [formerly 8ef320b07699c842ae0325e4665d570fa4399481] [formerly d171df23332dff1d33f00a7407f5dc3f6dde1ef7 [formerly d0fd97d943
]]
Former-commit-id: dc9a921b032e1acee0845186e7a009badbe768c5 [formerly 0c8a0f739bd1d984ca0db2b0623da5fdb813f4e0]
Former-commit-id: 3005cd15261952387fde1adf13770e2c1ee52749
This commit is contained in:
parent
c50a9b29bd
commit
9a54abfe62
24
cmd/root.go
24
cmd/root.go
@ -2,7 +2,6 @@ package cmd
|
||||
|
||||
import (
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net"
|
||||
@ -92,8 +91,8 @@ func mustGetStringViperFlag(flags *pflag.FlagSet, key string) string {
|
||||
|
||||
var rootCmd = &cobra.Command{
|
||||
Use: "filebrowser",
|
||||
Short: "A stylish web-based file browser",
|
||||
Version: version.Version,
|
||||
Short: "A stylish web-based file browser",
|
||||
Long: `File Browser CLI lets you create the database to use with File Browser,
|
||||
manage your users and all the configurations without acessing the
|
||||
web interface.
|
||||
@ -130,6 +129,8 @@ Also, if the database path doesn't exist, File Browser will enter into
|
||||
the quick setup mode and a new database will be bootstraped and a new
|
||||
user created with the credentials from options "username" and "password".`,
|
||||
Run: python(func(cmd *cobra.Command, args []string, d pythonData) {
|
||||
log.Println(cfgFile)
|
||||
|
||||
if !d.hadDB {
|
||||
quickSetup(cmd.Flags(), d)
|
||||
}
|
||||
@ -141,22 +142,23 @@ user created with the credentials from options "username" and "password".`,
|
||||
checkErr(err)
|
||||
server.Root = root
|
||||
|
||||
handler, err := fbhttp.NewHandler(d.store, server)
|
||||
checkErr(err)
|
||||
adr := server.Address + ":" + server.Port
|
||||
|
||||
var listener net.Listener
|
||||
|
||||
if server.TLSKey != "" && server.TLSCert != "" {
|
||||
cer, err := tls.LoadX509KeyPair(server.TLSCert, server.TLSKey)
|
||||
checkErr(err)
|
||||
config := &tls.Config{Certificates: []tls.Certificate{cer}}
|
||||
listener, err = tls.Listen("tcp", server.Address+":"+server.Port, config)
|
||||
listener, err = tls.Listen("tcp", adr, &tls.Config{Certificates: []tls.Certificate{cer}})
|
||||
checkErr(err)
|
||||
} else {
|
||||
listener, err = net.Listen("tcp", server.Address+":"+server.Port)
|
||||
listener, err = net.Listen("tcp", adr)
|
||||
checkErr(err)
|
||||
}
|
||||
|
||||
handler, err := fbhttp.NewHandler(d.store, server)
|
||||
checkErr(err)
|
||||
|
||||
log.Println("Listening on", listener.Addr().String())
|
||||
if err := http.Serve(listener, handler); err != nil {
|
||||
log.Fatal(err)
|
||||
@ -267,7 +269,7 @@ func quickSetup(flags *pflag.FlagSet, d pythonData) {
|
||||
}
|
||||
|
||||
if username == "" || password == "" {
|
||||
checkErr(errors.New("username and password cannot be empty during quick setup"))
|
||||
log.Fatal("username and password cannot be empty during quick setup")
|
||||
}
|
||||
|
||||
user := &users.User{
|
||||
@ -303,7 +305,9 @@ func initConfig() {
|
||||
if _, ok := err.(v.ConfigParseError); ok {
|
||||
panic(err)
|
||||
}
|
||||
// TODO: log.Println("No config file provided")
|
||||
cfgFile = "No config file used"
|
||||
} else {
|
||||
cfgFile = "Using config file: " + v.ConfigFileUsed()
|
||||
}
|
||||
// else TODO: log.Println("Using config file:", v.ConfigFileUsed())
|
||||
|
||||
}
|
||||
|
@ -43,14 +43,14 @@ func runRules(st *storage.Storage, cmd *cobra.Command, users func(*users.User),
|
||||
return
|
||||
}
|
||||
|
||||
settings, err := st.Settings.Get()
|
||||
s, err := st.Settings.Get()
|
||||
checkErr(err)
|
||||
|
||||
if global != nil {
|
||||
global(settings)
|
||||
global(s)
|
||||
}
|
||||
|
||||
printRules(settings.Rules, id)
|
||||
printRules(s.Rules, id)
|
||||
}
|
||||
|
||||
func getUserIdentifier(flags *pflag.FlagSet) interface{} {
|
||||
|
@ -26,8 +26,10 @@ options you want to change.`,
|
||||
password := mustGetString(flags, "password")
|
||||
newUsername := mustGetString(flags, "username")
|
||||
|
||||
var err error
|
||||
var user *users.User
|
||||
var (
|
||||
err error
|
||||
user *users.User
|
||||
)
|
||||
|
||||
if id != 0 {
|
||||
user, err = d.store.Users.Get("", id)
|
||||
|
@ -7,7 +7,7 @@ import (
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"github.com/dgrijalva/jwt-go"
|
||||
jwt "github.com/dgrijalva/jwt-go"
|
||||
"github.com/dgrijalva/jwt-go/request"
|
||||
"github.com/filebrowser/filebrowser/v2/errors"
|
||||
"github.com/filebrowser/filebrowser/v2/users"
|
||||
|
@ -9,7 +9,7 @@ import (
|
||||
"strings"
|
||||
"text/template"
|
||||
|
||||
"github.com/GeertJohan/go.rice"
|
||||
rice "github.com/GeertJohan/go.rice"
|
||||
"github.com/filebrowser/filebrowser/v2/auth"
|
||||
"github.com/filebrowser/filebrowser/v2/settings"
|
||||
"github.com/filebrowser/filebrowser/v2/storage"
|
||||
|
@ -13,8 +13,8 @@ import (
|
||||
"github.com/asdine/storm"
|
||||
"github.com/filebrowser/filebrowser/v2/settings"
|
||||
"github.com/filebrowser/filebrowser/v2/storage"
|
||||
"github.com/pelletier/go-toml"
|
||||
"gopkg.in/yaml.v2"
|
||||
toml "github.com/pelletier/go-toml"
|
||||
yaml "gopkg.in/yaml.v2"
|
||||
)
|
||||
|
||||
type oldDefs struct {
|
||||
@ -62,14 +62,14 @@ var defaults = &oldConf{
|
||||
},
|
||||
}
|
||||
|
||||
func importConf(db *storm.DB, path string, sto *storage.Storage) error {
|
||||
func readConf(path string) (*oldConf, error) {
|
||||
cfg := &oldConf{}
|
||||
if path != "" {
|
||||
ext := filepath.Ext(path)
|
||||
|
||||
fd, err := os.Open(path)
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
defer fd.Close()
|
||||
|
||||
@ -81,23 +81,32 @@ func importConf(db *storm.DB, path string, sto *storage.Storage) error {
|
||||
case ".yaml", ".yml":
|
||||
err = yaml.NewDecoder(fd).Decode(cfg)
|
||||
default:
|
||||
return errors.New("unsupported config extension " + ext)
|
||||
return nil, errors.New("unsupported config extension " + ext)
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
} else {
|
||||
cfg = defaults
|
||||
path, err := filepath.Abs(".")
|
||||
if err != nil {
|
||||
return err
|
||||
return nil, err
|
||||
}
|
||||
cfg.Defaults.Scope = path
|
||||
}
|
||||
return cfg, nil
|
||||
}
|
||||
|
||||
func importConf(db *storm.DB, path string, sto *storage.Storage) error {
|
||||
|
||||
cfg, err := readConf(path)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
commands := map[string][]string{}
|
||||
err := db.Get("config", "commands", &commands)
|
||||
err = db.Get("config", "commands", &commands)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@ -130,10 +139,10 @@ func importConf(db *storm.DB, path string, sto *storage.Storage) error {
|
||||
}
|
||||
|
||||
server := &settings.Server{
|
||||
BaseURL : cfg.BaseURL,
|
||||
Port : cfg.Port,
|
||||
Address : cfg.Address,
|
||||
Log : cfg.Log,
|
||||
BaseURL: cfg.BaseURL,
|
||||
Port: cfg.Port,
|
||||
Address: cfg.Address,
|
||||
Log: cfg.Log,
|
||||
}
|
||||
|
||||
var auther auth.Auther
|
||||
|
Loading…
Reference in New Issue
Block a user