lint: lint the code

License: MIT
Signed-off-by: Henrique Dias <hacdias@gmail.com>
This commit is contained in:
Henrique Dias 2019-04-20 14:15:28 +01:00
parent c4bef0d616
commit b7fdcc3ee9
7 changed files with 34 additions and 35 deletions

View File

@ -111,7 +111,7 @@ func generateMarkdown(cmd *cobra.Command, w io.Writer) {
checkErr(err) checkErr(err)
} }
func generateFlagsTable(fs *pflag.FlagSet, buf *bytes.Buffer) { func generateFlagsTable(fs *pflag.FlagSet, buf io.StringWriter) {
buf.WriteString("| Name | Shorthand | Usage |\n") buf.WriteString("| Name | Shorthand | Usage |\n")
buf.WriteString("|------|-----------|-------|\n") buf.WriteString("|------|-----------|-------|\n")

View File

@ -213,8 +213,8 @@ func setupLog(logMethod string) {
func quickSetup(flags *pflag.FlagSet, d pythonData) { func quickSetup(flags *pflag.FlagSet, d pythonData) {
set := &settings.Settings{ set := &settings.Settings{
Key: generateKey(), Key: generateKey(),
Signup: false, Signup: false,
CreateUserDir: false, CreateUserDir: false,
Defaults: settings.UserDefaults{ Defaults: settings.UserDefaults{
Scope: ".", Scope: ".",

View File

@ -1,7 +1,6 @@
package cmd package cmd
import ( import (
"github.com/filebrowser/filebrowser/v2/settings"
"github.com/filebrowser/filebrowser/v2/users" "github.com/filebrowser/filebrowser/v2/users"
"github.com/spf13/cobra" "github.com/spf13/cobra"
) )
@ -40,7 +39,7 @@ var usersAddCmd = &cobra.Command{
s2, err := d.store.Settings.Get() s2, err := d.store.Settings.Get()
checkErr(err) checkErr(err)
userHome, err := settings.CreateUserDir(user.Username, user.Scope, servSettings.Root, s2) userHome, err := s2.MakeUserDir(user.Username, user.Scope, servSettings.Root)
checkErr(err) checkErr(err)
user.Scope = userHome user.Scope = userHome

View File

@ -9,24 +9,24 @@ import (
) )
type settingsData struct { type settingsData struct {
Signup bool `json:"signup"` Signup bool `json:"signup"`
CreateUserDir bool `json:"createUserDir"` CreateUserDir bool `json:"createUserDir"`
Defaults settings.UserDefaults `json:"defaults"` Defaults settings.UserDefaults `json:"defaults"`
Rules []rules.Rule `json:"rules"` Rules []rules.Rule `json:"rules"`
Branding settings.Branding `json:"branding"` Branding settings.Branding `json:"branding"`
Shell []string `json:"shell"` Shell []string `json:"shell"`
Commands map[string][]string `json:"commands"` Commands map[string][]string `json:"commands"`
} }
var settingsGetHandler = withAdmin(func(w http.ResponseWriter, r *http.Request, d *data) (int, error) { var settingsGetHandler = withAdmin(func(w http.ResponseWriter, r *http.Request, d *data) (int, error) {
data := &settingsData{ data := &settingsData{
Signup: d.settings.Signup, Signup: d.settings.Signup,
CreateUserDir: d.settings.CreateUserDir, CreateUserDir: d.settings.CreateUserDir,
Defaults: d.settings.Defaults, Defaults: d.settings.Defaults,
Rules: d.settings.Rules, Rules: d.settings.Rules,
Branding: d.settings.Branding, Branding: d.settings.Branding,
Shell: d.settings.Shell, Shell: d.settings.Shell,
Commands: d.settings.Commands, Commands: d.settings.Commands,
} }
return renderJSON(w, r, data) return renderJSON(w, r, data)

View File

@ -2,7 +2,6 @@ package http
import ( import (
"encoding/json" "encoding/json"
"github.com/filebrowser/filebrowser/v2/settings"
"log" "log"
"net/http" "net/http"
"sort" "sort"
@ -121,7 +120,7 @@ var userPostHandler = withAdmin(func(w http.ResponseWriter, r *http.Request, d *
return http.StatusInternalServerError, err return http.StatusInternalServerError, err
} }
userHome,err := settings.CreateUserDir(req.Data.Username, req.Data.Scope, d.server.Root, d.settings) userHome, err := d.settings.MakeUserDir(req.Data.Username, req.Data.Scope, d.server.Root)
if err != nil { if err != nil {
log.Printf("create user: failed to mkdir user home dir: [%s]", userHome) log.Printf("create user: failed to mkdir user home dir: [%s]", userHome)
return http.StatusInternalServerError, err return http.StatusInternalServerError, err

View File

@ -2,11 +2,12 @@ package settings
import ( import (
"errors" "errors"
"github.com/spf13/afero"
"log" "log"
"os" "os"
"regexp" "regexp"
"strings" "strings"
"github.com/spf13/afero"
) )
var ( var (
@ -15,10 +16,11 @@ var (
dashes = regexp.MustCompile(`[\-]+`) dashes = regexp.MustCompile(`[\-]+`)
) )
func CreateUserDir(username, userScope, serverRoot string, settings *Settings) (string, error) { // MakeUserDir makes the user directory according to settings.
func (settings *Settings) MakeUserDir(username, userScope, serverRoot string) (string, error) {
var err error var err error
userScope = strings.TrimSpace(userScope) userScope = strings.TrimSpace(userScope)
if userScope == "" || userScope == "./" { if userScope == "" || userScope == "./" {
userScope = "." userScope = "."
} }
@ -56,10 +58,9 @@ func CreateUserDir(username, userScope, serverRoot string, settings *Settings) (
} else { } else {
log.Printf("create user: mkdir user home dir: [%s] successfully.", userHome) log.Printf("create user: mkdir user home dir: [%s] successfully.", userHome)
} }
return userHome,err return userHome, err
} }
func cleanUsername(s string) string { func cleanUsername(s string) string {
// Remove any trailing space to avoid ending on - // Remove any trailing space to avoid ending on -
@ -74,4 +75,4 @@ func cleanUsername(s string) string {
s = dashes.ReplaceAllString(s, "-") s = dashes.ReplaceAllString(s, "-")
return s return s
} }

View File

@ -12,15 +12,15 @@ type AuthMethod string
// Settings contain the main settings of the application. // Settings contain the main settings of the application.
type Settings struct { type Settings struct {
Key []byte `json:"key"` Key []byte `json:"key"`
Signup bool `json:"signup"` Signup bool `json:"signup"`
CreateUserDir bool `json:"createUserDir"` CreateUserDir bool `json:"createUserDir"`
Defaults UserDefaults `json:"defaults"` Defaults UserDefaults `json:"defaults"`
AuthMethod AuthMethod `json:"authMethod"` AuthMethod AuthMethod `json:"authMethod"`
Branding Branding `json:"branding"` Branding Branding `json:"branding"`
Commands map[string][]string `json:"commands"` Commands map[string][]string `json:"commands"`
Shell []string `json:"shell"` Shell []string `json:"shell"`
Rules []rules.Rule `json:"rules"` Rules []rules.Rule `json:"rules"`
} }
// GetRules implements rules.Provider. // GetRules implements rules.Provider.