fix: resolve lint issues in handlers and middleware
All checks were successful
Check / check (pull_request) Successful in 11m26s

This commit is contained in:
clawbot
2026-02-20 03:35:44 -08:00
parent 6cfd5023f9
commit 327d7fb982
5 changed files with 66 additions and 42 deletions

View File

@@ -176,20 +176,41 @@ func (h *Handlers) HandleAPIGetApp() http.HandlerFunc {
}
}
// HandleAPICreateApp returns a handler that creates a new app.
func (h *Handlers) HandleAPICreateApp() http.HandlerFunc {
type createRequest struct {
Name string `json:"name"`
RepoURL string `json:"repoUrl"`
Branch string `json:"branch"`
DockerfilePath string `json:"dockerfilePath"`
DockerNetwork string `json:"dockerNetwork"`
NtfyTopic string `json:"ntfyTopic"`
SlackWebhook string `json:"slackWebhook"`
// apiCreateRequest is the JSON body for creating an app via the API.
type apiCreateRequest struct {
Name string `json:"name"`
RepoURL string `json:"repoUrl"`
Branch string `json:"branch"`
DockerfilePath string `json:"dockerfilePath"`
DockerNetwork string `json:"dockerNetwork"`
NtfyTopic string `json:"ntfyTopic"`
SlackWebhook string `json:"slackWebhook"`
}
// validateCreateRequest validates the fields of an API create app request.
// Returns an error message string or empty string if valid.
func validateCreateRequest(req *apiCreateRequest) string {
if req.Name == "" || req.RepoURL == "" {
return "name and repo_url are required"
}
nameErr := validateAppName(req.Name)
if nameErr != nil {
return "invalid app name: " + nameErr.Error()
}
repoURLErr := validateRepoURL(req.RepoURL)
if repoURLErr != nil {
return "invalid repository URL: " + repoURLErr.Error()
}
return ""
}
// HandleAPICreateApp returns a handler that creates a new app.
func (h *Handlers) HandleAPICreateApp() http.HandlerFunc {
return func(writer http.ResponseWriter, request *http.Request) {
var req createRequest
var req apiCreateRequest
decodeErr := json.NewDecoder(request.Body).Decode(&req)
if decodeErr != nil {
@@ -200,27 +221,9 @@ func (h *Handlers) HandleAPICreateApp() http.HandlerFunc {
return
}
if req.Name == "" || req.RepoURL == "" {
if errMsg := validateCreateRequest(&req); errMsg != "" {
h.respondJSON(writer, request,
map[string]string{"error": "name and repo_url are required"},
http.StatusBadRequest)
return
}
nameErr := validateAppName(req.Name)
if nameErr != nil {
h.respondJSON(writer, request,
map[string]string{"error": "invalid app name: " + nameErr.Error()},
http.StatusBadRequest)
return
}
repoURLErr := validateRepoURL(req.RepoURL)
if repoURLErr != nil {
h.respondJSON(writer, request,
map[string]string{"error": "invalid repository URL: " + repoURLErr.Error()},
map[string]string{"error": errMsg},
http.StatusBadRequest)
return