api: run go fmt
This commit is contained in:
		| @@ -5,15 +5,15 @@ import ( | |||||||
| ) | ) | ||||||
|  |  | ||||||
| type comment struct { | type comment struct { | ||||||
| 	CommentHex    string    `json:"commentHex"` | 	CommentHex   string    `json:"commentHex"` | ||||||
| 	Domain        string    `json:"domain,omitempty"` | 	Domain       string    `json:"domain,omitempty"` | ||||||
| 	Path          string    `json:"url,omitempty"` | 	Path         string    `json:"url,omitempty"` | ||||||
| 	CommenterHex  string    `json:"commenterHex"` | 	CommenterHex string    `json:"commenterHex"` | ||||||
| 	Markdown      string    `json:"markdown"` | 	Markdown     string    `json:"markdown"` | ||||||
| 	Html          string    `json:"html"` | 	Html         string    `json:"html"` | ||||||
| 	ParentHex     string    `json:"parentHex"` | 	ParentHex    string    `json:"parentHex"` | ||||||
| 	Score         int       `json:"score"` | 	Score        int       `json:"score"` | ||||||
| 	State         string    `json:"state"` | 	State        string    `json:"state"` | ||||||
| 	CreationDate  time.Time `json:"creationDate"` | 	CreationDate time.Time `json:"creationDate"` | ||||||
| 	Direction     int       `json:"direction"` | 	Direction    int       `json:"direction"` | ||||||
| } | } | ||||||
|   | |||||||
| @@ -1,6 +1,6 @@ | |||||||
| package main | package main | ||||||
|  |  | ||||||
| import() | import () | ||||||
|  |  | ||||||
| func commentStatistics(domain string) ([]int64, error) { | func commentStatistics(domain string) ([]int64, error) { | ||||||
| 	statement := ` | 	statement := ` | ||||||
|   | |||||||
| @@ -32,7 +32,7 @@ func commenterNew(email string, name string, link string, photo string, provider | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	passwordHash := []byte{} | 	passwordHash := []byte{} | ||||||
| 	if (password != "") { | 	if password != "" { | ||||||
| 		passwordHash, err = bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost) | 		passwordHash, err = bcrypt.GenerateFromPassword([]byte(password), bcrypt.DefaultCost) | ||||||
| 		if err != nil { | 		if err != nil { | ||||||
| 			logger.Errorf("cannot generate hash from password: %v\n", err) | 			logger.Errorf("cannot generate hash from password: %v\n", err) | ||||||
| @@ -54,7 +54,6 @@ func commenterNew(email string, name string, link string, photo string, provider | |||||||
| 	return commenterHex, nil | 	return commenterHex, nil | ||||||
| } | } | ||||||
|  |  | ||||||
|  |  | ||||||
| func commenterNewHandler(w http.ResponseWriter, r *http.Request) { | func commenterNewHandler(w http.ResponseWriter, r *http.Request) { | ||||||
| 	type request struct { | 	type request struct { | ||||||
| 		Email    *string `json:"email"` | 		Email    *string `json:"email"` | ||||||
|   | |||||||
| @@ -2,8 +2,8 @@ package main | |||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"os" | 	"os" | ||||||
| 	"strings" |  | ||||||
| 	"path/filepath" | 	"path/filepath" | ||||||
|  | 	"strings" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| func parseConfig() error { | func parseConfig() error { | ||||||
| @@ -29,15 +29,15 @@ func parseConfig() error { | |||||||
| 		"SMTP_PORT":         "", | 		"SMTP_PORT":         "", | ||||||
| 		"SMTP_FROM_ADDRESS": "", | 		"SMTP_FROM_ADDRESS": "", | ||||||
|  |  | ||||||
| 		"GOOGLE_KEY":        "", | 		"GOOGLE_KEY":    "", | ||||||
| 		"GOOGLE_SECRET":     "", | 		"GOOGLE_SECRET": "", | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	for key, value := range defaults { | 	for key, value := range defaults { | ||||||
| 		if os.Getenv("COMMENTO_" + key) == "" { | 		if os.Getenv("COMMENTO_"+key) == "" { | ||||||
| 			os.Setenv(key, value) | 			os.Setenv(key, value) | ||||||
| 		} else { | 		} else { | ||||||
| 			os.Setenv(key, os.Getenv("COMMENTO_" + key)) | 			os.Setenv(key, os.Getenv("COMMENTO_"+key)) | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| @@ -55,7 +55,7 @@ func parseConfig() error { | |||||||
|  |  | ||||||
| 	static := os.Getenv("STATIC") | 	static := os.Getenv("STATIC") | ||||||
| 	for strings.HasSuffix(static, "/") { | 	for strings.HasSuffix(static, "/") { | ||||||
| 		static = static[0:len(static)-1] | 		static = static[0 : len(static)-1] | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	file, err := os.Stat(static) | 	file, err := os.Stat(static) | ||||||
|   | |||||||
| @@ -2,8 +2,8 @@ package main | |||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"os" | 	"os" | ||||||
| 	"testing" |  | ||||||
| 	"path/filepath" | 	"path/filepath" | ||||||
|  | 	"testing" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| func TestParseConfigBasics(t *testing.T) { | func TestParseConfigBasics(t *testing.T) { | ||||||
|   | |||||||
| @@ -37,7 +37,7 @@ func googleOauthConfigure() error { | |||||||
| 		Endpoint: google.Endpoint, | 		Endpoint: google.Endpoint, | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	configuredOauths = append(configuredOauths, "google"); | 	configuredOauths = append(configuredOauths, "google") | ||||||
|  |  | ||||||
| 	return nil | 	return nil | ||||||
| } | } | ||||||
|   | |||||||
| @@ -6,10 +6,10 @@ import ( | |||||||
| 	"github.com/gorilla/mux" | 	"github.com/gorilla/mux" | ||||||
| 	"html/template" | 	"html/template" | ||||||
| 	"io/ioutil" | 	"io/ioutil" | ||||||
|  | 	"mime" | ||||||
| 	"net/http" | 	"net/http" | ||||||
| 	"os" | 	"os" | ||||||
| 	"path" | 	"path" | ||||||
| 	"mime" |  | ||||||
| ) | ) | ||||||
|  |  | ||||||
| func redirectLogin(w http.ResponseWriter, r *http.Request) { | func redirectLogin(w http.ResponseWriter, r *http.Request) { | ||||||
| @@ -52,7 +52,7 @@ func initStaticRouter(router *mux.Router) error { | |||||||
| 				prefix += "window.commento_cdn='" + os.Getenv("CDN_PREFIX") + "';\n" | 				prefix += "window.commento_cdn='" + os.Getenv("CDN_PREFIX") + "';\n" | ||||||
| 			} | 			} | ||||||
|  |  | ||||||
| 			asset[p] = prefix + string(contents); | 			asset[p] = prefix + string(contents) | ||||||
|  |  | ||||||
| 			router.HandleFunc(p, func(w http.ResponseWriter, r *http.Request) { | 			router.HandleFunc(p, func(w http.ResponseWriter, r *http.Request) { | ||||||
| 				w.Header().Set("Content-Type", mime.TypeByExtension(path.Ext(r.URL.Path))) | 				w.Header().Set("Content-Type", mime.TypeByExtension(path.Ext(r.URL.Path))) | ||||||
| @@ -95,7 +95,7 @@ func initStaticRouter(router *mux.Router) error { | |||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	for _, page := range pages { | 	for _, page := range pages { | ||||||
| 		router.HandleFunc("/" + page, func(w http.ResponseWriter, r *http.Request) { | 		router.HandleFunc("/"+page, func(w http.ResponseWriter, r *http.Request) { | ||||||
| 			fmt.Fprint(w, html[r.URL.Path]) | 			fmt.Fprint(w, html[r.URL.Path]) | ||||||
| 		}) | 		}) | ||||||
| 	} | 	} | ||||||
|   | |||||||
| @@ -18,7 +18,7 @@ func smtpOwnerConfirmHex(to string, toName string, confirmHex string) error { | |||||||
| 	var body bytes.Buffer | 	var body bytes.Buffer | ||||||
| 	templates["confirm-hex"].Execute(&body, &ownerConfirmHexPlugs{Origin: os.Getenv("ORIGIN"), ConfirmHex: confirmHex}) | 	templates["confirm-hex"].Execute(&body, &ownerConfirmHexPlugs{Origin: os.Getenv("ORIGIN"), ConfirmHex: confirmHex}) | ||||||
|  |  | ||||||
| 	err := smtp.SendMail(os.Getenv("SMTP_HOST") + ":" + os.Getenv("SMTP_PORT"), smtpAuth, os.Getenv("SMTP_FROM_ADDRESS"), []string{to}, concat(header, body)) | 	err := smtp.SendMail(os.Getenv("SMTP_HOST")+":"+os.Getenv("SMTP_PORT"), smtpAuth, os.Getenv("SMTP_FROM_ADDRESS"), []string{to}, concat(header, body)) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		logger.Errorf("cannot send confirmation email: %v", err) | 		logger.Errorf("cannot send confirmation email: %v", err) | ||||||
| 		return errorCannotSendEmail | 		return errorCannotSendEmail | ||||||
|   | |||||||
| @@ -18,7 +18,7 @@ func smtpOwnerResetHex(to string, toName string, resetHex string) error { | |||||||
| 	var body bytes.Buffer | 	var body bytes.Buffer | ||||||
| 	templates["reset-hex"].Execute(&body, &ownerResetHexPlugs{Origin: os.Getenv("ORIGIN"), ResetHex: resetHex}) | 	templates["reset-hex"].Execute(&body, &ownerResetHexPlugs{Origin: os.Getenv("ORIGIN"), ResetHex: resetHex}) | ||||||
|  |  | ||||||
| 	err := smtp.SendMail(os.Getenv("SMTP_HOST") + ":" + os.Getenv("SMTP_PORT"), smtpAuth, os.Getenv("SMTP_FROM_ADDRESS"), []string{to}, concat(header, body)) | 	err := smtp.SendMail(os.Getenv("SMTP_HOST")+":"+os.Getenv("SMTP_PORT"), smtpAuth, os.Getenv("SMTP_FROM_ADDRESS"), []string{to}, concat(header, body)) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		logger.Errorf("cannot send reset email: %v", err) | 		logger.Errorf("cannot send reset email: %v", err) | ||||||
| 		return errorCannotSendEmail | 		return errorCannotSendEmail | ||||||
|   | |||||||
| @@ -1,9 +1,9 @@ | |||||||
| package main | package main | ||||||
|  |  | ||||||
| import ( | import ( | ||||||
| 	"os" |  | ||||||
| 	"fmt" | 	"fmt" | ||||||
| 	"html/template" | 	"html/template" | ||||||
|  | 	"os" | ||||||
| ) | ) | ||||||
|  |  | ||||||
| var headerTemplate *template.Template | var headerTemplate *template.Template | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user