Chore: linter complains
This commit is contained in:
		| @@ -10,10 +10,8 @@ linters: | |||||||
|     - fatcontext |     - fatcontext | ||||||
|     - govet |     - govet | ||||||
|     - ineffassign |     - ineffassign | ||||||
|     - noctx |  | ||||||
|     - perfsprint |     - perfsprint | ||||||
|     - prealloc |     - prealloc | ||||||
|     - staticcheck |  | ||||||
|     - unused |     - unused | ||||||
|   settings: |   settings: | ||||||
|     funlen: |     funlen: | ||||||
|   | |||||||
| @@ -17,11 +17,17 @@ import ( | |||||||
| func abortWithError(w http.ResponseWriter, msg string) { | func abortWithError(w http.ResponseWriter, msg string) { | ||||||
| 	w.WriteHeader(200) // must be 200 for htmx to replace components | 	w.WriteHeader(200) // must be 200 for htmx to replace components | ||||||
| 	tmpl := template.Must(template.ParseGlob("components/*.html")) | 	tmpl := template.Must(template.ParseGlob("components/*.html")) | ||||||
| 	tmpl.ExecuteTemplate(w, "error", msg) | 	if err := tmpl.ExecuteTemplate(w, "error", msg); err != nil { | ||||||
|  | 		log.Error("failed to execute error template", "error", err) | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| func HandleNameCheck(w http.ResponseWriter, r *http.Request) { | func HandleNameCheck(w http.ResponseWriter, r *http.Request) { | ||||||
| 	r.ParseForm() | 	if err := r.ParseForm(); err != nil { | ||||||
|  | 		log.Error("failed to parse form", "error", err) | ||||||
|  | 		abortWithError(w, err.Error()) | ||||||
|  | 		return | ||||||
|  | 	} | ||||||
| 	username := r.PostFormValue("username") | 	username := r.PostFormValue("username") | ||||||
| 	if username == "" { | 	if username == "" { | ||||||
| 		msg := "username not provided" | 		msg := "username not provided" | ||||||
| @@ -40,10 +46,14 @@ func HandleNameCheck(w http.ResponseWriter, r *http.Request) { | |||||||
| 	if utils.StrInSlice(cleanName, allNames) { | 	if utils.StrInSlice(cleanName, allNames) { | ||||||
| 		err := fmt.Errorf("name: %s already taken", cleanName) | 		err := fmt.Errorf("name: %s already taken", cleanName) | ||||||
| 		log.Warn("already taken", "error", err) | 		log.Warn("already taken", "error", err) | ||||||
| 		tmpl.ExecuteTemplate(w, "namecheck", 2) | 		if err := tmpl.ExecuteTemplate(w, "namecheck", 2); err != nil { | ||||||
|  | 			log.Error("failed to execute namecheck template", "error", err) | ||||||
|  | 		} | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	tmpl.ExecuteTemplate(w, "namecheck", 0) | 	if err := tmpl.ExecuteTemplate(w, "namecheck", 0); err != nil { | ||||||
|  | 		log.Error("failed to execute namecheck template", "error", err) | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| func HandleFrontLogin(w http.ResponseWriter, r *http.Request) { | func HandleFrontLogin(w http.ResponseWriter, r *http.Request) { | ||||||
| @@ -106,7 +116,9 @@ func HandleFrontLogin(w http.ResponseWriter, r *http.Request) { | |||||||
| 			return | 			return | ||||||
| 		} | 		} | ||||||
| 	} | 	} | ||||||
| 	tmpl.ExecuteTemplate(w, "base", fi) | 	if err := tmpl.ExecuteTemplate(w, "base", fi); err != nil { | ||||||
|  | 		log.Error("failed to execute base template", "error", err) | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| func makeCookie(username string, remote string) (*http.Cookie, error) { | func makeCookie(username string, remote string) (*http.Cookie, error) { | ||||||
|   | |||||||
| @@ -15,7 +15,9 @@ func HandleShowCreateForm(w http.ResponseWriter, r *http.Request) { | |||||||
| 		abortWithError(w, err.Error()) | 		abortWithError(w, err.Error()) | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	tmpl.ExecuteTemplate(w, "createform", show) | 	if err := tmpl.ExecuteTemplate(w, "createform", show); err != nil { | ||||||
|  | 		log.Error("failed to execute createform template", "error", err) | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| func HandleHideCreateForm(w http.ResponseWriter, r *http.Request) { | func HandleHideCreateForm(w http.ResponseWriter, r *http.Request) { | ||||||
| @@ -25,7 +27,9 @@ func HandleHideCreateForm(w http.ResponseWriter, r *http.Request) { | |||||||
| 		abortWithError(w, err.Error()) | 		abortWithError(w, err.Error()) | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	tmpl.ExecuteTemplate(w, "createform", show) | 	if err := tmpl.ExecuteTemplate(w, "createform", show); err != nil { | ||||||
|  | 		log.Error("failed to execute createform template", "error", err) | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| func HandleShowColor(w http.ResponseWriter, r *http.Request) { | func HandleShowColor(w http.ResponseWriter, r *http.Request) { | ||||||
| @@ -107,7 +111,9 @@ func HandleShowColor(w http.ResponseWriter, r *http.Request) { | |||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	notify(models.NotifyRoomUpdatePrefix+fi.Room.ID, "") | 	notify(models.NotifyRoomUpdatePrefix+fi.Room.ID, "") | ||||||
| 	tmpl.ExecuteTemplate(w, "cardword", cardword) | 	if err := tmpl.ExecuteTemplate(w, "cardword", cardword); err != nil { | ||||||
|  | 		log.Error("failed to execute cardword template", "error", err) | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| func HandleActionHistory(w http.ResponseWriter, r *http.Request) { | func HandleActionHistory(w http.ResponseWriter, r *http.Request) { | ||||||
| @@ -121,7 +127,9 @@ func HandleActionHistory(w http.ResponseWriter, r *http.Request) { | |||||||
| 		abortWithError(w, err.Error()) | 		abortWithError(w, err.Error()) | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	tmpl.ExecuteTemplate(w, "actionhistory", fi.Room.ActionHistory) | 	if err := tmpl.ExecuteTemplate(w, "actionhistory", fi.Room.ActionHistory); err != nil { | ||||||
|  | 		log.Error("failed to execute actionhistory template", "error", err) | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| func HandleAddBot(w http.ResponseWriter, r *http.Request) { | func HandleAddBot(w http.ResponseWriter, r *http.Request) { | ||||||
|   | |||||||
| @@ -46,7 +46,9 @@ func HandleCreateRoom(w http.ResponseWriter, r *http.Request) { | |||||||
| 		abortWithError(w, err.Error()) | 		abortWithError(w, err.Error()) | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	tmpl.ExecuteTemplate(w, "base", fi) | 	if err := tmpl.ExecuteTemplate(w, "base", fi); err != nil { | ||||||
|  | 		log.Error("failed to execute base template", "error", err) | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| // DEPRACATED: duplication of HandleJoinRoom | // DEPRACATED: duplication of HandleJoinRoom | ||||||
| @@ -97,7 +99,11 @@ func HandleCreateRoom(w http.ResponseWriter, r *http.Request) { | |||||||
| // } | // } | ||||||
|  |  | ||||||
| func HandleJoinTeam(w http.ResponseWriter, r *http.Request) { | func HandleJoinTeam(w http.ResponseWriter, r *http.Request) { | ||||||
| 	r.ParseForm() | 	if err := r.ParseForm(); err != nil { | ||||||
|  | 		log.Error("failed to parse form", "error", err) | ||||||
|  | 		abortWithError(w, err.Error()) | ||||||
|  | 		return | ||||||
|  | 	} | ||||||
| 	team := r.PostFormValue("team") | 	team := r.PostFormValue("team") | ||||||
| 	role := r.PostFormValue("role") | 	role := r.PostFormValue("role") | ||||||
| 	if team == "" || role == "" { | 	if team == "" || role == "" { | ||||||
| @@ -133,7 +139,9 @@ func HandleJoinTeam(w http.ResponseWriter, r *http.Request) { | |||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	notify(models.NotifyRoomUpdatePrefix+fi.Room.ID, "") | 	notify(models.NotifyRoomUpdatePrefix+fi.Room.ID, "") | ||||||
| 	tmpl.ExecuteTemplate(w, "base", fi) | 	if err := tmpl.ExecuteTemplate(w, "base", fi); err != nil { | ||||||
|  | 		log.Error("failed to execute base template", "error", err) | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| func HandleEndTurn(w http.ResponseWriter, r *http.Request) { | func HandleEndTurn(w http.ResponseWriter, r *http.Request) { | ||||||
| @@ -172,7 +180,9 @@ func HandleEndTurn(w http.ResponseWriter, r *http.Request) { | |||||||
| 		bot.SignalsCh <- true | 		bot.SignalsCh <- true | ||||||
| 	} | 	} | ||||||
| 	notify(models.NotifyRoomUpdatePrefix+fi.Room.ID, "") | 	notify(models.NotifyRoomUpdatePrefix+fi.Room.ID, "") | ||||||
| 	tmpl.ExecuteTemplate(w, "base", fi) | 	if err := tmpl.ExecuteTemplate(w, "base", fi); err != nil { | ||||||
|  | 		log.Error("failed to execute base template", "error", err) | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| func HandleStartGame(w http.ResponseWriter, r *http.Request) { | func HandleStartGame(w http.ResponseWriter, r *http.Request) { | ||||||
| @@ -226,7 +236,9 @@ func HandleStartGame(w http.ResponseWriter, r *http.Request) { | |||||||
| 	// to update only the room that should be updated | 	// to update only the room that should be updated | ||||||
| 	notify(models.NotifyRoomUpdatePrefix+fi.Room.ID, "") | 	notify(models.NotifyRoomUpdatePrefix+fi.Room.ID, "") | ||||||
| 	// notify(models.NotifyBacklogPrefix+fi.Room.ID, "game started") | 	// notify(models.NotifyBacklogPrefix+fi.Room.ID, "game started") | ||||||
| 	tmpl.ExecuteTemplate(w, "room", fi) | 	if err := tmpl.ExecuteTemplate(w, "room", fi); err != nil { | ||||||
|  | 		log.Error("failed to execute room template", "error", err) | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| func HandleJoinRoom(w http.ResponseWriter, r *http.Request) { | func HandleJoinRoom(w http.ResponseWriter, r *http.Request) { | ||||||
| @@ -246,7 +258,9 @@ func HandleJoinRoom(w http.ResponseWriter, r *http.Request) { | |||||||
| 		// INFO: if non-loggined user join: prompt to login | 		// INFO: if non-loggined user join: prompt to login | ||||||
| 		fi = &models.FullInfo{} | 		fi = &models.FullInfo{} | ||||||
| 		fi.LinkLogin = roomID | 		fi.LinkLogin = roomID | ||||||
| 		tmpl.ExecuteTemplate(w, "base", fi) | 		if err := tmpl.ExecuteTemplate(w, "base", fi); err != nil { | ||||||
|  | 			log.Error("failed to execute base template", "error", err) | ||||||
|  | 		} | ||||||
| 		// abortWithError(w, err.Error()) | 		// abortWithError(w, err.Error()) | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| @@ -258,7 +272,9 @@ func HandleJoinRoom(w http.ResponseWriter, r *http.Request) { | |||||||
| 		abortWithError(w, err.Error()) | 		abortWithError(w, err.Error()) | ||||||
| 		return | 		return | ||||||
| 	} | 	} | ||||||
| 	tmpl.ExecuteTemplate(w, "room", fi) | 	if err := tmpl.ExecuteTemplate(w, "room", fi); err != nil { | ||||||
|  | 		log.Error("failed to execute room template", "error", err) | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| func HandleGiveClue(w http.ResponseWriter, r *http.Request) { | func HandleGiveClue(w http.ResponseWriter, r *http.Request) { | ||||||
|   | |||||||
| @@ -30,7 +30,9 @@ func init() { | |||||||
| } | } | ||||||
|  |  | ||||||
| func HandlePing(w http.ResponseWriter, r *http.Request) { | func HandlePing(w http.ResponseWriter, r *http.Request) { | ||||||
| 	w.Write([]byte("pong")) | 	if _, err := w.Write([]byte("pong")); err != nil { | ||||||
|  | 		log.Error("failed to write ping response", "error", err) | ||||||
|  | 	} | ||||||
| } | } | ||||||
|  |  | ||||||
| func HandleHome(w http.ResponseWriter, r *http.Request) { | func HandleHome(w http.ResponseWriter, r *http.Request) { | ||||||
|   | |||||||
| @@ -188,7 +188,7 @@ func (b *Bot) CallLLM(prompt string) error { | |||||||
| 	} | 	} | ||||||
| 	req.Header.Add("Content-Type", "application/json") | 	req.Header.Add("Content-Type", "application/json") | ||||||
| 	req.Header.Add("Accept", "application/json") | 	req.Header.Add("Accept", "application/json") | ||||||
| 	req.Header.Add("Authorization", fmt.Sprintf("Bearer %s", b.cfg.LLMConfig.TOKEN)) | 	req.Header.Add("Authorization", "Bearer "+b.cfg.LLMConfig.TOKEN) | ||||||
| 	res, err := client.Do(req) | 	res, err := client.Do(req) | ||||||
| 	if err != nil { | 	if err != nil { | ||||||
| 		fmt.Println(err) | 		fmt.Println(err) | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user
	 Grail Finder
					Grail Finder