mirror of
https://github.com/Luzifer/cloudkeys-go.git
synced 2024-11-09 22:50:05 +00:00
Fixed linter errors
This commit is contained in:
parent
e83e9100e4
commit
dc3fb4df50
8 changed files with 19 additions and 12 deletions
|
@ -15,6 +15,8 @@ type config struct {
|
||||||
|
|
||||||
CookieSigningKey string `flag:"cookie-authkey" description:"Key used to authenticate the session"`
|
CookieSigningKey string `flag:"cookie-authkey" description:"Key used to authenticate the session"`
|
||||||
CookieEncryptKey string `flag:"cookie-encryptkey" description:"Key used to encrypt 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) {
|
func (c config) ParsedStorage() (*url.URL, error) {
|
||||||
|
|
|
@ -21,7 +21,7 @@ func httpHelper(f httpHelperFunc) http.HandlerFunc {
|
||||||
|
|
||||||
template, err := f(res, r, sess, &ctx)
|
template, err := f(res, r, sess, &ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
http.Error(res, err.Error(), http.StatusInternalServerError)
|
http.Error(res, "An error ocurred.", http.StatusInternalServerError)
|
||||||
fmt.Printf("ERR: %s\n", err)
|
fmt.Printf("ERR: %s\n", err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -61,6 +61,6 @@ func simpleTemplateOutput(template string) httpHelperFunc {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func String(s string) *string {
|
func stringPointer(s string) *string {
|
||||||
return &s
|
return &s
|
||||||
}
|
}
|
||||||
|
|
4
login.go
4
login.go
|
@ -19,7 +19,7 @@ func loginHandler(res http.ResponseWriter, r *http.Request, session *sessions.Se
|
||||||
|
|
||||||
if !storage.IsPresent(createUserFilename(username)) {
|
if !storage.IsPresent(createUserFilename(username)) {
|
||||||
(*ctx)["error"] = true
|
(*ctx)["error"] = true
|
||||||
return String("login.html"), nil
|
return stringPointer("login.html"), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
userFileRaw, err := storage.Read(createUserFilename(username))
|
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 {
|
if userFile.MetaData.Password != password {
|
||||||
(*ctx)["error"] = true
|
(*ctx)["error"] = true
|
||||||
return String("login.html"), nil
|
return stringPointer("login.html"), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
auth, ok := session.Values["authorizedAccounts"].(authorizedAccounts)
|
auth, ok := session.Values["authorizedAccounts"].(authorizedAccounts)
|
||||||
|
|
5
main.go
5
main.go
|
@ -22,6 +22,11 @@ var (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
|
if cfg.VersionAndQuit {
|
||||||
|
fmt.Printf("cloudkeys-go %s\n", version)
|
||||||
|
os.Exit(0)
|
||||||
|
}
|
||||||
|
|
||||||
if _, err := cfg.ParsedStorage(); err != nil {
|
if _, err := cfg.ParsedStorage(); err != nil {
|
||||||
fmt.Printf("ERR: Please provide a valid storage URI\n")
|
fmt.Printf("ERR: Please provide a valid storage URI\n")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
|
|
|
@ -30,5 +30,5 @@ func overviewHandler(res http.ResponseWriter, r *http.Request, session *sessions
|
||||||
(*ctx)["authorized_accounts"] = frontendAccounts
|
(*ctx)["authorized_accounts"] = frontendAccounts
|
||||||
(*ctx)["current_user_index"] = idx
|
(*ctx)["current_user_index"] = idx
|
||||||
|
|
||||||
return String("overview.html"), nil
|
return stringPointer("overview.html"), nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,12 +18,12 @@ func registerHandler(res http.ResponseWriter, r *http.Request, session *sessions
|
||||||
)
|
)
|
||||||
|
|
||||||
if username == "" || password == "" || password != passwordCheck {
|
if username == "" || password == "" || password != passwordCheck {
|
||||||
return String("register.html"), nil
|
return stringPointer("register.html"), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
if storage.IsPresent(createUserFilename(username)) {
|
if storage.IsPresent(createUserFilename(username)) {
|
||||||
(*ctx)["exists"] = true
|
(*ctx)["exists"] = true
|
||||||
return String("register.html"), nil
|
return stringPointer("register.html"), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
d := dataObject{}
|
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 {
|
if err := storage.Write(createUserFilename(username), data); err == nil {
|
||||||
(*ctx)["created"] = true
|
(*ctx)["created"] = true
|
||||||
return String("register.html"), nil
|
return stringPointer("register.html"), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return nil, err // TODO: Handle in-app?
|
return nil, err // TODO: Handle in-app?
|
||||||
|
|
|
@ -11,7 +11,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registerStorage("local", NewLocalStorage)
|
registerStorage("local", newLocalStorage)
|
||||||
}
|
}
|
||||||
|
|
||||||
// LocalStorage implements a storage option for local file storage
|
// 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
|
// 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:]
|
p := u.Path[1:]
|
||||||
|
|
||||||
if len(p) == 0 {
|
if len(p) == 0 {
|
||||||
|
|
|
@ -14,7 +14,7 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
registerStorage("s3", NewS3Storage)
|
registerStorage("s3", newS3Storage)
|
||||||
}
|
}
|
||||||
|
|
||||||
// S3Storage implements a storage option for Amazon S3
|
// 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
|
// 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{
|
return &S3Storage{
|
||||||
bucket: u.Host,
|
bucket: u.Host,
|
||||||
path: u.Path,
|
path: u.Path,
|
||||||
|
|
Loading…
Reference in a new issue