Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added Init config variable. #46

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ type Config struct {
Debug bool
Updater updater.Config
Lcf bool

Init string
}

// Defaults set the default value for some variables
Expand Down Expand Up @@ -71,5 +73,9 @@ func (cfg *Config) Defaults() error {
}
}

if cfg.Init == "" {
cfg.Init = "init"
}

return nil
}
2 changes: 2 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ func main() {
Debug bool
Updater updater.Config
ModificationHash string
Init string
}{
ConfigFile: filepath.Base(cfgPath),
Now: time.Now().String(),
Expand All @@ -158,6 +159,7 @@ func main() {
Debug: cfg.Debug,
Updater: cfg.Updater,
ModificationHash: modHash,
Init: cfg.Init,
}

tmpl, err := t.Exec()
Expand Down
2 changes: 1 addition & 1 deletion template/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import (
// {{exportedTitle "File"}}{{buildSafeVarName .Path}} is "{{.Path}}"
var {{exportedTitle "File"}}{{buildSafeVarName .Path}} = {{.Data}}

func init() {
func {{ .Init}}() {
{{if .Compression.Compress}}
{{if not .Compression.Keep}}
rb := bytes.NewReader({{exportedTitle "File"}}{{buildSafeVarName .Path}})
Expand Down
16 changes: 8 additions & 8 deletions template/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ import (
{{end}}
)

var (
var (
// CTX is a context for webdav vfs
{{exported "CTX"}} = context.Background()

Expand Down Expand Up @@ -62,7 +62,7 @@ var {{exportedTitle "File"}}{{buildSafeVarName .Path}} = {{.Data}}
{{end}}
{{end}}

func init() {
func {{ .Init}}() {
err := {{exported "CTX"}}.Err()
if err != nil {
panic(err)
Expand Down Expand Up @@ -232,7 +232,7 @@ func {{exportedTitle "WalkDirs"}}(name string, includeDirsInList bool, files ...
if err != nil {
return nil, err
}

err = f.Close()
if err != nil {
return nil, err
Expand Down Expand Up @@ -278,7 +278,7 @@ type {{exportedTitle "Server"}} struct {
Files []string
}

// Init sets the routes and basic http auth
// Init sets the routes and basic http auth
// before starting the http server
func (s *{{exportedTitle "Server"}}) Init() {
s.Auth = {{exportedTitle "Auth"}}{
Expand All @@ -301,7 +301,7 @@ func (s *{{exportedTitle "Server"}}) Init() {
// Get gives a list of file names and hashes
func (s *{{exportedTitle "Server"}}) Get(c echo.Context) error {
log.Println("[fileb0x.Server]: Hashing server files...")

// file:hash
hashes := map[string]string{}

Expand Down Expand Up @@ -335,7 +335,7 @@ func (s *{{exportedTitle "Server"}}) Get(c echo.Context) error {
})
}

// Post is used to upload a file and replace
// Post is used to upload a file and replace
// it in the virtual memory file system
func (s *{{exportedTitle "Server"}}) Post(c echo.Context) error {
file, err := c.FormFile("file")
Expand All @@ -358,7 +358,7 @@ func (s *{{exportedTitle "Server"}}) Post(c echo.Context) error {
log.Println("[fileb0x.Server]: Creating dir tree", newDir)
list := strings.Split(newDir, "/")
var tree string

for _, dir := range list {
if dir == "" || dir == "." || dir == "/" || dir == "./" {
continue
Expand Down Expand Up @@ -392,7 +392,7 @@ func (s *{{exportedTitle "Server"}}) Post(c echo.Context) error {
return c.String(http.StatusOK, "ok")
}

// BasicAuth is a middleware to check if
// BasicAuth is a middleware to check if
// the username and password are valid
// echo's middleware isn't used because of golint issues
func (s *{{exportedTitle "Server"}}) BasicAuth() echo.MiddlewareFunc {
Expand Down