diff --git a/config.go b/config.go index d4ec519..490a0a4 100644 --- a/config.go +++ b/config.go @@ -15,6 +15,8 @@ type config struct { CookieSigningKey string `flag:"cookie-authkey" description:"Key used to authenticate the session"` CookieEncryptKey string `flag:"cookie-encryptkey" description:"Key used to encrypt the session"` + + VersionAndQuit bool `flag:"version" default:"false" description:"Show version and quit"` } func (c config) ParsedStorage() (*url.URL, error) { diff --git a/httpHelper.go b/httpHelper.go index e801c5c..27e5fd0 100644 --- a/httpHelper.go +++ b/httpHelper.go @@ -21,7 +21,7 @@ func httpHelper(f httpHelperFunc) http.HandlerFunc { template, err := f(res, r, sess, &ctx) if err != nil { - http.Error(res, err.Error(), http.StatusInternalServerError) + http.Error(res, "An error ocurred.", http.StatusInternalServerError) fmt.Printf("ERR: %s\n", err) return } @@ -61,6 +61,6 @@ func simpleTemplateOutput(template string) httpHelperFunc { } } -func String(s string) *string { +func stringPointer(s string) *string { return &s } diff --git a/login.go b/login.go index 69bffc3..494396b 100644 --- a/login.go +++ b/login.go @@ -19,7 +19,7 @@ func loginHandler(res http.ResponseWriter, r *http.Request, session *sessions.Se if !storage.IsPresent(createUserFilename(username)) { (*ctx)["error"] = true - return String("login.html"), nil + return stringPointer("login.html"), nil } userFileRaw, err := storage.Read(createUserFilename(username)) @@ -34,7 +34,7 @@ func loginHandler(res http.ResponseWriter, r *http.Request, session *sessions.Se if userFile.MetaData.Password != password { (*ctx)["error"] = true - return String("login.html"), nil + return stringPointer("login.html"), nil } auth, ok := session.Values["authorizedAccounts"].(authorizedAccounts) diff --git a/main.go b/main.go index 1d64811..61c7e62 100644 --- a/main.go +++ b/main.go @@ -22,6 +22,11 @@ var ( ) func init() { + if cfg.VersionAndQuit { + fmt.Printf("cloudkeys-go %s\n", version) + os.Exit(0) + } + if _, err := cfg.ParsedStorage(); err != nil { fmt.Printf("ERR: Please provide a valid storage URI\n") os.Exit(1) diff --git a/overview.go b/overview.go index eacff35..2b729b9 100644 --- a/overview.go +++ b/overview.go @@ -30,5 +30,5 @@ func overviewHandler(res http.ResponseWriter, r *http.Request, session *sessions (*ctx)["authorized_accounts"] = frontendAccounts (*ctx)["current_user_index"] = idx - return String("overview.html"), nil + return stringPointer("overview.html"), nil } diff --git a/register.go b/register.go index 660fdcb..fbea71e 100644 --- a/register.go +++ b/register.go @@ -18,12 +18,12 @@ func registerHandler(res http.ResponseWriter, r *http.Request, session *sessions ) if username == "" || password == "" || password != passwordCheck { - return String("register.html"), nil + return stringPointer("register.html"), nil } if storage.IsPresent(createUserFilename(username)) { (*ctx)["exists"] = true - return String("register.html"), nil + return stringPointer("register.html"), nil } d := dataObject{} @@ -35,7 +35,7 @@ func registerHandler(res http.ResponseWriter, r *http.Request, session *sessions if err := storage.Write(createUserFilename(username), data); err == nil { (*ctx)["created"] = true - return String("register.html"), nil + return stringPointer("register.html"), nil } return nil, err // TODO: Handle in-app? diff --git a/storageLocal.go b/storageLocal.go index 1938eed..57e2b34 100644 --- a/storageLocal.go +++ b/storageLocal.go @@ -11,7 +11,7 @@ import ( ) func init() { - registerStorage("local", NewLocalStorage) + registerStorage("local", newLocalStorage) } // LocalStorage implements a storage option for local file storage @@ -20,7 +20,7 @@ type LocalStorage struct { } // NewLocalStorage checks config, creates the path and initializes a LocalStorage -func NewLocalStorage(u *url.URL) (storageAdapter, error) { +func newLocalStorage(u *url.URL) (storageAdapter, error) { p := u.Path[1:] if len(p) == 0 { diff --git a/storageS3.go b/storageS3.go index d553b28..9903e12 100644 --- a/storageS3.go +++ b/storageS3.go @@ -14,7 +14,7 @@ import ( ) func init() { - registerStorage("s3", NewS3Storage) + registerStorage("s3", newS3Storage) } // S3Storage implements a storage option for Amazon S3 @@ -25,7 +25,7 @@ type S3Storage struct { } // NewS3Storage checks config, creates the path and initializes a S3Storage -func NewS3Storage(u *url.URL) (storageAdapter, error) { +func newS3Storage(u *url.URL) (storageAdapter, error) { return &S3Storage{ bucket: u.Host, path: u.Path,