Merge pull request #66 from gabriel-samfira/add-aditional-checks
Fix linting errors and add workflow to check
This commit is contained in:
commit
e96caf4711
31 changed files with 383 additions and 205 deletions
34
.github/workflows/go-tests.yml
vendored
34
.github/workflows/go-tests.yml
vendored
|
|
@ -8,10 +8,40 @@ on:
|
|||
branches:
|
||||
- main
|
||||
|
||||
concurrency:
|
||||
group: ${{ github.workflow }}-${{ github.head_ref || github.ref_name }}
|
||||
cancel-in-progress: true
|
||||
|
||||
permissions: {}
|
||||
|
||||
jobs:
|
||||
linters:
|
||||
name: Linters
|
||||
runs-on: ubuntu-20.04
|
||||
timeout-minutes: 10
|
||||
|
||||
steps:
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y libbtrfs-dev build-essential
|
||||
|
||||
- uses: actions/setup-go@v3
|
||||
with:
|
||||
go-version: 'stable'
|
||||
- uses: actions/checkout@v3
|
||||
- uses: golangci/golangci-lint-action@v3
|
||||
with:
|
||||
skip-cache: true
|
||||
args: --timeout=8m --build-tags testing
|
||||
- name: Verify go vendor, go modules and gofmt
|
||||
run: |
|
||||
sudo apt-get install -y jq
|
||||
make verify
|
||||
|
||||
go-tests:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
needs: [linters]
|
||||
steps:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v3
|
||||
|
|
@ -24,4 +54,4 @@ jobs:
|
|||
- run: go version
|
||||
|
||||
- name: Run GARM Go Tests
|
||||
run: make test
|
||||
run: make go-test
|
||||
|
|
|
|||
19
Makefile
19
Makefile
|
|
@ -4,6 +4,9 @@ IMAGE_TAG = garm-build
|
|||
|
||||
USER_ID=$(shell ((docker --version | grep -q podman) && echo "0" || id -u))
|
||||
USER_GROUP=$(shell ((docker --version | grep -q podman) && echo "0" || id -g))
|
||||
ROOTDIR=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))
|
||||
GO ?= go
|
||||
|
||||
|
||||
default: build-static
|
||||
|
||||
|
|
@ -15,5 +18,19 @@ build-static:
|
|||
@echo Binaries are available in $(PWD)/bin
|
||||
|
||||
.PHONY: test
|
||||
test:
|
||||
test: verify go-test
|
||||
|
||||
go-test:
|
||||
go test -race -mod=vendor -tags testing -v $(TEST_ARGS) -timeout=15m -parallel=4 -count=1 ./...
|
||||
|
||||
fmtcheck:
|
||||
@gofmt -l -s $$(go list ./... | sed 's|garm/||g') | grep ".*\.go"; if [ "$$?" -eq 0 ]; then echo "gofmt check failed; please tun gofmt -w -s"; exit 1;fi
|
||||
|
||||
verify-vendor: ## verify if all the go.mod/go.sum files are up-to-date
|
||||
$(eval TMPDIR := $(shell mktemp -d))
|
||||
@cp -R ${ROOTDIR} ${TMPDIR}
|
||||
@(cd ${TMPDIR}/garm && ${GO} mod tidy)
|
||||
@diff -r -u -q ${ROOTDIR} ${TMPDIR}/garm
|
||||
@rm -rf ${TMPDIR}
|
||||
|
||||
verify: verify-vendor fmtcheck
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ package controllers
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"io"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
|
|
@ -79,29 +79,14 @@ func handleError(w http.ResponseWriter, err error) {
|
|||
apiErr.Details = ""
|
||||
}
|
||||
|
||||
json.NewEncoder(w).Encode(apiErr)
|
||||
}
|
||||
|
||||
func (a *APIController) authenticateHook(body []byte, headers http.Header) error {
|
||||
// signature := headers.Get("X-Hub-Signature-256")
|
||||
hookType := headers.Get("X-Github-Hook-Installation-Target-Type")
|
||||
var workflowJob runnerParams.WorkflowJob
|
||||
if err := json.Unmarshal(body, &workflowJob); err != nil {
|
||||
return gErrors.NewBadRequestError("invalid post body: %s", err)
|
||||
if err := json.NewEncoder(w).Encode(apiErr); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
|
||||
switch hookType {
|
||||
case "repository":
|
||||
case "organization":
|
||||
default:
|
||||
return gErrors.NewBadRequestError("invalid hook type: %s", hookType)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *APIController) handleWorkflowJobEvent(w http.ResponseWriter, r *http.Request) {
|
||||
defer r.Body.Close()
|
||||
body, err := ioutil.ReadAll(r.Body)
|
||||
body, err := io.ReadAll(r.Body)
|
||||
if err != nil {
|
||||
handleError(w, gErrors.NewBadRequestError("invalid post body: %s", err))
|
||||
return
|
||||
|
|
@ -137,7 +122,9 @@ func (a *APIController) WSHandler(writer http.ResponseWriter, req *http.Request)
|
|||
ctx := req.Context()
|
||||
if !auth.IsAdmin(ctx) {
|
||||
writer.WriteHeader(http.StatusForbidden)
|
||||
writer.Write([]byte("you need admin level access to view logs"))
|
||||
if _, err := writer.Write([]byte("you need admin level access to view logs")); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -177,7 +164,9 @@ func (a *APIController) NotFoundHandler(w http.ResponseWriter, r *http.Request)
|
|||
}
|
||||
w.WriteHeader(http.StatusNotFound)
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(apiErr)
|
||||
if err := json.NewEncoder(w).Encode(apiErr); err != nil {
|
||||
log.Printf("failet to write response: %q", err)
|
||||
}
|
||||
}
|
||||
|
||||
// LoginHandler returns a jwt token
|
||||
|
|
@ -206,7 +195,9 @@ func (a *APIController) LoginHandler(w http.ResponseWriter, r *http.Request) {
|
|||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(runnerParams.JWTResponse{Token: tokenString})
|
||||
if err := json.NewEncoder(w).Encode(runnerParams.JWTResponse{Token: tokenString}); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *APIController) FirstRunHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -230,7 +221,9 @@ func (a *APIController) FirstRunHandler(w http.ResponseWriter, r *http.Request)
|
|||
return
|
||||
}
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(newUser)
|
||||
if err := json.NewEncoder(w).Encode(newUser); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *APIController) ListCredentials(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -242,7 +235,9 @@ func (a *APIController) ListCredentials(w http.ResponseWriter, r *http.Request)
|
|||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(creds)
|
||||
if err := json.NewEncoder(w).Encode(creds); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *APIController) ListProviders(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -254,5 +249,7 @@ func (a *APIController) ListProviders(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(providers)
|
||||
if err := json.NewEncoder(w).Encode(providers); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,9 @@ func (a *APIController) CreateEnterpriseHandler(w http.ResponseWriter, r *http.R
|
|||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(enterprise)
|
||||
if err := json.NewEncoder(w).Encode(enterprise); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *APIController) ListEnterprisesHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -57,7 +59,9 @@ func (a *APIController) ListEnterprisesHandler(w http.ResponseWriter, r *http.Re
|
|||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(enterprise)
|
||||
if err := json.NewEncoder(w).Encode(enterprise); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *APIController) GetEnterpriseByIDHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -67,10 +71,12 @@ func (a *APIController) GetEnterpriseByIDHandler(w http.ResponseWriter, r *http.
|
|||
enterpriseID, ok := vars["enterpriseID"]
|
||||
if !ok {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
if err := json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
Error: "Bad Request",
|
||||
Details: "No enterprise ID specified",
|
||||
})
|
||||
}); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -82,7 +88,9 @@ func (a *APIController) GetEnterpriseByIDHandler(w http.ResponseWriter, r *http.
|
|||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(enterprise)
|
||||
if err := json.NewEncoder(w).Encode(enterprise); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *APIController) DeleteEnterpriseHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -92,10 +100,12 @@ func (a *APIController) DeleteEnterpriseHandler(w http.ResponseWriter, r *http.R
|
|||
enterpriseID, ok := vars["enterpriseID"]
|
||||
if !ok {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
if err := json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
Error: "Bad Request",
|
||||
Details: "No enterprise ID specified",
|
||||
})
|
||||
}); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -117,10 +127,12 @@ func (a *APIController) UpdateEnterpriseHandler(w http.ResponseWriter, r *http.R
|
|||
enterpriseID, ok := vars["enterpriseID"]
|
||||
if !ok {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
if err := json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
Error: "Bad Request",
|
||||
Details: "No enterprise ID specified",
|
||||
})
|
||||
}); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -138,7 +150,9 @@ func (a *APIController) UpdateEnterpriseHandler(w http.ResponseWriter, r *http.R
|
|||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(enterprise)
|
||||
if err := json.NewEncoder(w).Encode(enterprise); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *APIController) CreateEnterprisePoolHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -148,10 +162,12 @@ func (a *APIController) CreateEnterprisePoolHandler(w http.ResponseWriter, r *ht
|
|||
enterpriseID, ok := vars["enterpriseID"]
|
||||
if !ok {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
if err := json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
Error: "Bad Request",
|
||||
Details: "No enterprise ID specified",
|
||||
})
|
||||
}); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -170,7 +186,9 @@ func (a *APIController) CreateEnterprisePoolHandler(w http.ResponseWriter, r *ht
|
|||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(pool)
|
||||
if err := json.NewEncoder(w).Encode(pool); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *APIController) ListEnterprisePoolsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -179,10 +197,12 @@ func (a *APIController) ListEnterprisePoolsHandler(w http.ResponseWriter, r *htt
|
|||
enterpriseID, ok := vars["enterpriseID"]
|
||||
if !ok {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
if err := json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
Error: "Bad Request",
|
||||
Details: "No enterprise ID specified",
|
||||
})
|
||||
}); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -194,7 +214,10 @@ func (a *APIController) ListEnterprisePoolsHandler(w http.ResponseWriter, r *htt
|
|||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(pools)
|
||||
if err := json.NewEncoder(w).Encode(pools); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
func (a *APIController) GetEnterprisePoolHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -204,10 +227,12 @@ func (a *APIController) GetEnterprisePoolHandler(w http.ResponseWriter, r *http.
|
|||
poolID, poolOk := vars["poolID"]
|
||||
if !enterpriseOk || !poolOk {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
if err := json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
Error: "Bad Request",
|
||||
Details: "No enterprise or pool ID specified",
|
||||
})
|
||||
}); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -219,7 +244,9 @@ func (a *APIController) GetEnterprisePoolHandler(w http.ResponseWriter, r *http.
|
|||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(pool)
|
||||
if err := json.NewEncoder(w).Encode(pool); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *APIController) DeleteEnterprisePoolHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -230,10 +257,12 @@ func (a *APIController) DeleteEnterprisePoolHandler(w http.ResponseWriter, r *ht
|
|||
poolID, poolOk := vars["poolID"]
|
||||
if !enterpriseOk || !poolOk {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
if err := json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
Error: "Bad Request",
|
||||
Details: "No enterprise or pool ID specified",
|
||||
})
|
||||
}); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -256,10 +285,12 @@ func (a *APIController) UpdateEnterprisePoolHandler(w http.ResponseWriter, r *ht
|
|||
poolID, poolOk := vars["poolID"]
|
||||
if !enterpriseOk || !poolOk {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
if err := json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
Error: "Bad Request",
|
||||
Details: "No enterprise or pool ID specified",
|
||||
})
|
||||
}); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -278,5 +309,7 @@ func (a *APIController) UpdateEnterprisePoolHandler(w http.ResponseWriter, r *ht
|
|||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(pool)
|
||||
if err := json.NewEncoder(w).Encode(pool); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -32,10 +32,12 @@ func (a *APIController) ListPoolInstancesHandler(w http.ResponseWriter, r *http.
|
|||
poolID, ok := vars["poolID"]
|
||||
if !ok {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
if err := json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
Error: "Bad Request",
|
||||
Details: "No pool ID specified",
|
||||
})
|
||||
}); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -47,7 +49,9 @@ func (a *APIController) ListPoolInstancesHandler(w http.ResponseWriter, r *http.
|
|||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(instances)
|
||||
if err := json.NewEncoder(w).Encode(instances); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *APIController) GetInstanceHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -56,10 +60,12 @@ func (a *APIController) GetInstanceHandler(w http.ResponseWriter, r *http.Reques
|
|||
instanceName, ok := vars["instanceName"]
|
||||
if !ok {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
if err := json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
Error: "Bad Request",
|
||||
Details: "No runner name specified",
|
||||
})
|
||||
}); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -71,7 +77,9 @@ func (a *APIController) GetInstanceHandler(w http.ResponseWriter, r *http.Reques
|
|||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(instance)
|
||||
if err := json.NewEncoder(w).Encode(instance); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *APIController) DeleteInstanceHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -80,10 +88,12 @@ func (a *APIController) DeleteInstanceHandler(w http.ResponseWriter, r *http.Req
|
|||
instanceName, ok := vars["instanceName"]
|
||||
if !ok {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
if err := json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
Error: "Bad Request",
|
||||
Details: "No instance name specified",
|
||||
})
|
||||
}); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -103,10 +113,12 @@ func (a *APIController) ListRepoInstancesHandler(w http.ResponseWriter, r *http.
|
|||
repoID, ok := vars["repoID"]
|
||||
if !ok {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
if err := json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
Error: "Bad Request",
|
||||
Details: "No repo ID specified",
|
||||
})
|
||||
}); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -118,7 +130,9 @@ func (a *APIController) ListRepoInstancesHandler(w http.ResponseWriter, r *http.
|
|||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(instances)
|
||||
if err := json.NewEncoder(w).Encode(instances); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *APIController) ListOrgInstancesHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -127,10 +141,12 @@ func (a *APIController) ListOrgInstancesHandler(w http.ResponseWriter, r *http.R
|
|||
orgID, ok := vars["orgID"]
|
||||
if !ok {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
if err := json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
Error: "Bad Request",
|
||||
Details: "No org ID specified",
|
||||
})
|
||||
}); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -142,7 +158,9 @@ func (a *APIController) ListOrgInstancesHandler(w http.ResponseWriter, r *http.R
|
|||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(instances)
|
||||
if err := json.NewEncoder(w).Encode(instances); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *APIController) ListEnterpriseInstancesHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -151,10 +169,12 @@ func (a *APIController) ListEnterpriseInstancesHandler(w http.ResponseWriter, r
|
|||
enterpriseID, ok := vars["enterpriseID"]
|
||||
if !ok {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
if err := json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
Error: "Bad Request",
|
||||
Details: "No enterprise ID specified",
|
||||
})
|
||||
}); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -166,7 +186,9 @@ func (a *APIController) ListEnterpriseInstancesHandler(w http.ResponseWriter, r
|
|||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(instances)
|
||||
if err := json.NewEncoder(w).Encode(instances); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *APIController) ListAllInstancesHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -180,7 +202,9 @@ func (a *APIController) ListAllInstancesHandler(w http.ResponseWriter, r *http.R
|
|||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(instances)
|
||||
if err := json.NewEncoder(w).Encode(instances); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *APIController) InstanceStatusMessageHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -214,5 +238,7 @@ func (a *APIController) InstanceGithubRegistrationTokenHandler(w http.ResponseWr
|
|||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte(token))
|
||||
if _, err := w.Write([]byte(token)); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,9 @@ func (a *APIController) CreateOrgHandler(w http.ResponseWriter, r *http.Request)
|
|||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(repo)
|
||||
if err := json.NewEncoder(w).Encode(repo); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *APIController) ListOrgsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -57,7 +59,9 @@ func (a *APIController) ListOrgsHandler(w http.ResponseWriter, r *http.Request)
|
|||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(orgs)
|
||||
if err := json.NewEncoder(w).Encode(orgs); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *APIController) GetOrgByIDHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -67,10 +71,12 @@ func (a *APIController) GetOrgByIDHandler(w http.ResponseWriter, r *http.Request
|
|||
orgID, ok := vars["orgID"]
|
||||
if !ok {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
if err := json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
Error: "Bad Request",
|
||||
Details: "No org ID specified",
|
||||
})
|
||||
}); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -82,7 +88,9 @@ func (a *APIController) GetOrgByIDHandler(w http.ResponseWriter, r *http.Request
|
|||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(org)
|
||||
if err := json.NewEncoder(w).Encode(org); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *APIController) DeleteOrgHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -92,10 +100,12 @@ func (a *APIController) DeleteOrgHandler(w http.ResponseWriter, r *http.Request)
|
|||
orgID, ok := vars["orgID"]
|
||||
if !ok {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
if err := json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
Error: "Bad Request",
|
||||
Details: "No org ID specified",
|
||||
})
|
||||
}); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -117,10 +127,12 @@ func (a *APIController) UpdateOrgHandler(w http.ResponseWriter, r *http.Request)
|
|||
orgID, ok := vars["orgID"]
|
||||
if !ok {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
if err := json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
Error: "Bad Request",
|
||||
Details: "No org ID specified",
|
||||
})
|
||||
}); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -138,7 +150,9 @@ func (a *APIController) UpdateOrgHandler(w http.ResponseWriter, r *http.Request)
|
|||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(org)
|
||||
if err := json.NewEncoder(w).Encode(org); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *APIController) CreateOrgPoolHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -148,10 +162,12 @@ func (a *APIController) CreateOrgPoolHandler(w http.ResponseWriter, r *http.Requ
|
|||
orgID, ok := vars["orgID"]
|
||||
if !ok {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
if err := json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
Error: "Bad Request",
|
||||
Details: "No org ID specified",
|
||||
})
|
||||
}); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -170,7 +186,9 @@ func (a *APIController) CreateOrgPoolHandler(w http.ResponseWriter, r *http.Requ
|
|||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(pool)
|
||||
if err := json.NewEncoder(w).Encode(pool); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *APIController) ListOrgPoolsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -179,10 +197,12 @@ func (a *APIController) ListOrgPoolsHandler(w http.ResponseWriter, r *http.Reque
|
|||
orgID, ok := vars["orgID"]
|
||||
if !ok {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
if err := json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
Error: "Bad Request",
|
||||
Details: "No org ID specified",
|
||||
})
|
||||
}); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -194,7 +214,9 @@ func (a *APIController) ListOrgPoolsHandler(w http.ResponseWriter, r *http.Reque
|
|||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(pools)
|
||||
if err := json.NewEncoder(w).Encode(pools); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *APIController) GetOrgPoolHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -204,10 +226,12 @@ func (a *APIController) GetOrgPoolHandler(w http.ResponseWriter, r *http.Request
|
|||
poolID, poolOk := vars["poolID"]
|
||||
if !repoOk || !poolOk {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
if err := json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
Error: "Bad Request",
|
||||
Details: "No org or pool ID specified",
|
||||
})
|
||||
}); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -219,7 +243,9 @@ func (a *APIController) GetOrgPoolHandler(w http.ResponseWriter, r *http.Request
|
|||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(pool)
|
||||
if err := json.NewEncoder(w).Encode(pool); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *APIController) DeleteOrgPoolHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -230,10 +256,12 @@ func (a *APIController) DeleteOrgPoolHandler(w http.ResponseWriter, r *http.Requ
|
|||
poolID, poolOk := vars["poolID"]
|
||||
if !orgOk || !poolOk {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
if err := json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
Error: "Bad Request",
|
||||
Details: "No org or pool ID specified",
|
||||
})
|
||||
}); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -256,10 +284,12 @@ func (a *APIController) UpdateOrgPoolHandler(w http.ResponseWriter, r *http.Requ
|
|||
poolID, poolOk := vars["poolID"]
|
||||
if !orgOk || !poolOk {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
if err := json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
Error: "Bad Request",
|
||||
Details: "No org or pool ID specified",
|
||||
})
|
||||
}); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -278,5 +308,7 @@ func (a *APIController) UpdateOrgPoolHandler(w http.ResponseWriter, r *http.Requ
|
|||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(pool)
|
||||
if err := json.NewEncoder(w).Encode(pool); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -38,7 +38,9 @@ func (a *APIController) ListAllPoolsHandler(w http.ResponseWriter, r *http.Reque
|
|||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(pools)
|
||||
if err := json.NewEncoder(w).Encode(pools); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *APIController) GetPoolByIDHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -48,10 +50,12 @@ func (a *APIController) GetPoolByIDHandler(w http.ResponseWriter, r *http.Reques
|
|||
poolID, ok := vars["poolID"]
|
||||
if !ok {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
if err := json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
Error: "Bad Request",
|
||||
Details: "No pool ID specified",
|
||||
})
|
||||
}); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -65,7 +69,9 @@ func (a *APIController) GetPoolByIDHandler(w http.ResponseWriter, r *http.Reques
|
|||
pool.RunnerBootstrapTimeout = pool.RunnerTimeout()
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(pool)
|
||||
if err := json.NewEncoder(w).Encode(pool); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *APIController) DeletePoolByIDHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -75,10 +81,12 @@ func (a *APIController) DeletePoolByIDHandler(w http.ResponseWriter, r *http.Req
|
|||
poolID, ok := vars["poolID"]
|
||||
if !ok {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
if err := json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
Error: "Bad Request",
|
||||
Details: "No pool ID specified",
|
||||
})
|
||||
}); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -99,10 +107,12 @@ func (a *APIController) UpdatePoolByIDHandler(w http.ResponseWriter, r *http.Req
|
|||
poolID, ok := vars["poolID"]
|
||||
if !ok {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
if err := json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
Error: "Bad Request",
|
||||
Details: "No pool ID specified",
|
||||
})
|
||||
}); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -121,6 +131,7 @@ func (a *APIController) UpdatePoolByIDHandler(w http.ResponseWriter, r *http.Req
|
|||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(pool)
|
||||
|
||||
if err := json.NewEncoder(w).Encode(pool); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,7 +43,9 @@ func (a *APIController) CreateRepoHandler(w http.ResponseWriter, r *http.Request
|
|||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(repo)
|
||||
if err := json.NewEncoder(w).Encode(repo); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *APIController) ListReposHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -57,7 +59,9 @@ func (a *APIController) ListReposHandler(w http.ResponseWriter, r *http.Request)
|
|||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(repos)
|
||||
if err := json.NewEncoder(w).Encode(repos); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *APIController) GetRepoByIDHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -67,10 +71,12 @@ func (a *APIController) GetRepoByIDHandler(w http.ResponseWriter, r *http.Reques
|
|||
repoID, ok := vars["repoID"]
|
||||
if !ok {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
if err := json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
Error: "Bad Request",
|
||||
Details: "No repo ID specified",
|
||||
})
|
||||
}); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -82,7 +88,9 @@ func (a *APIController) GetRepoByIDHandler(w http.ResponseWriter, r *http.Reques
|
|||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(repo)
|
||||
if err := json.NewEncoder(w).Encode(repo); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *APIController) DeleteRepoHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -92,10 +100,12 @@ func (a *APIController) DeleteRepoHandler(w http.ResponseWriter, r *http.Request
|
|||
repoID, ok := vars["repoID"]
|
||||
if !ok {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
if err := json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
Error: "Bad Request",
|
||||
Details: "No repo ID specified",
|
||||
})
|
||||
}); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -117,10 +127,12 @@ func (a *APIController) UpdateRepoHandler(w http.ResponseWriter, r *http.Request
|
|||
repoID, ok := vars["repoID"]
|
||||
if !ok {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
if err := json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
Error: "Bad Request",
|
||||
Details: "No repo ID specified",
|
||||
})
|
||||
}); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -138,7 +150,9 @@ func (a *APIController) UpdateRepoHandler(w http.ResponseWriter, r *http.Request
|
|||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(repo)
|
||||
if err := json.NewEncoder(w).Encode(repo); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *APIController) CreateRepoPoolHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -148,10 +162,12 @@ func (a *APIController) CreateRepoPoolHandler(w http.ResponseWriter, r *http.Req
|
|||
repoID, ok := vars["repoID"]
|
||||
if !ok {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
if err := json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
Error: "Bad Request",
|
||||
Details: "No repo ID specified",
|
||||
})
|
||||
}); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -170,7 +186,9 @@ func (a *APIController) CreateRepoPoolHandler(w http.ResponseWriter, r *http.Req
|
|||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(pool)
|
||||
if err := json.NewEncoder(w).Encode(pool); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *APIController) ListRepoPoolsHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -179,10 +197,12 @@ func (a *APIController) ListRepoPoolsHandler(w http.ResponseWriter, r *http.Requ
|
|||
repoID, ok := vars["repoID"]
|
||||
if !ok {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
if err := json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
Error: "Bad Request",
|
||||
Details: "No repo ID specified",
|
||||
})
|
||||
}); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -194,7 +214,9 @@ func (a *APIController) ListRepoPoolsHandler(w http.ResponseWriter, r *http.Requ
|
|||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(pools)
|
||||
if err := json.NewEncoder(w).Encode(pools); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *APIController) GetRepoPoolHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -204,10 +226,12 @@ func (a *APIController) GetRepoPoolHandler(w http.ResponseWriter, r *http.Reques
|
|||
poolID, poolOk := vars["poolID"]
|
||||
if !repoOk || !poolOk {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
if err := json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
Error: "Bad Request",
|
||||
Details: "No repo or pool ID specified",
|
||||
})
|
||||
}); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -219,7 +243,9 @@ func (a *APIController) GetRepoPoolHandler(w http.ResponseWriter, r *http.Reques
|
|||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(pool)
|
||||
if err := json.NewEncoder(w).Encode(pool); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
}
|
||||
|
||||
func (a *APIController) DeleteRepoPoolHandler(w http.ResponseWriter, r *http.Request) {
|
||||
|
|
@ -230,10 +256,12 @@ func (a *APIController) DeleteRepoPoolHandler(w http.ResponseWriter, r *http.Req
|
|||
poolID, poolOk := vars["poolID"]
|
||||
if !repoOk || !poolOk {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
if err := json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
Error: "Bad Request",
|
||||
Details: "No repo or pool ID specified",
|
||||
})
|
||||
}); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -256,10 +284,12 @@ func (a *APIController) UpdateRepoPoolHandler(w http.ResponseWriter, r *http.Req
|
|||
poolID, poolOk := vars["poolID"]
|
||||
if !repoOk || !poolOk {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
if err := json.NewEncoder(w).Encode(params.APIErrorResponse{
|
||||
Error: "Bad Request",
|
||||
Details: "No repo or pool ID specified",
|
||||
})
|
||||
}); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -278,5 +308,7 @@ func (a *APIController) UpdateRepoPoolHandler(w http.ResponseWriter, r *http.Req
|
|||
}
|
||||
|
||||
w.Header().Set("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(pool)
|
||||
if err := json.NewEncoder(w).Encode(pool); err != nil {
|
||||
log.Printf("failed to encode response: %q", err)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,11 +42,7 @@ type Authenticator struct {
|
|||
}
|
||||
|
||||
func (a *Authenticator) IsInitialized() bool {
|
||||
if a.store.HasAdminUser(context.Background()) {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
return a.store.HasAdminUser(context.Background())
|
||||
}
|
||||
|
||||
func (a *Authenticator) GetJWTToken(ctx context.Context) (string, error) {
|
||||
|
|
|
|||
|
|
@ -157,20 +157,6 @@ func FullName(ctx context.Context) string {
|
|||
return name.(string)
|
||||
}
|
||||
|
||||
// SetJWTClaim will set the JWT claim in the context
|
||||
func SetJWTClaim(ctx context.Context, claim JWTClaims) context.Context {
|
||||
return context.WithValue(ctx, jwtTokenFlag, claim)
|
||||
}
|
||||
|
||||
// JWTClaim returns the JWT claim saved in the context
|
||||
func JWTClaim(ctx context.Context) JWTClaims {
|
||||
jwtClaim := ctx.Value(jwtTokenFlag)
|
||||
if jwtClaim == nil {
|
||||
return JWTClaims{}
|
||||
}
|
||||
return jwtClaim.(JWTClaims)
|
||||
}
|
||||
|
||||
// SetIsEnabled sets a flag indicating if account is enabled
|
||||
func SetIsEnabled(ctx context.Context, enabled bool) context.Context {
|
||||
return context.WithValue(ctx, isEnabledFlag, enabled)
|
||||
|
|
|
|||
|
|
@ -16,6 +16,7 @@ package auth
|
|||
|
||||
import (
|
||||
"encoding/json"
|
||||
"log"
|
||||
"net/http"
|
||||
|
||||
"garm/apiserver/params"
|
||||
|
|
@ -40,7 +41,9 @@ func (i *initRequired) Middleware(next http.Handler) http.Handler {
|
|||
if err != nil || ctrlInfo.ControllerID.String() == "" {
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
w.WriteHeader(http.StatusConflict)
|
||||
json.NewEncoder(w).Encode(params.InitializationRequired)
|
||||
if err := json.NewEncoder(w).Encode(params.InitializationRequired); err != nil {
|
||||
log.Printf("failed to encode response: %s", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
ctx := r.Context()
|
||||
|
|
|
|||
|
|
@ -73,7 +73,6 @@ func NewInstanceJWTToken(instance params.Instance, secret, entity string, poolTy
|
|||
// used with gorilla
|
||||
type instanceMiddleware struct {
|
||||
store dbCommon.Store
|
||||
auth *Authenticator
|
||||
cfg config.JWTAuth
|
||||
}
|
||||
|
||||
|
|
@ -156,7 +155,6 @@ func (amw *instanceMiddleware) Middleware(next http.Handler) http.Handler {
|
|||
return
|
||||
}
|
||||
|
||||
// ctx = SetJWTClaim(ctx, *claims)
|
||||
next.ServeHTTP(w, r.WithContext(ctx))
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ import (
|
|||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"log"
|
||||
"net/http"
|
||||
"strings"
|
||||
|
||||
|
|
@ -42,7 +43,6 @@ type JWTClaims struct {
|
|||
// used with gorilla
|
||||
type jwtMiddleware struct {
|
||||
store dbCommon.Store
|
||||
auth *Authenticator
|
||||
cfg config.JWTAuth
|
||||
}
|
||||
|
||||
|
|
@ -75,10 +75,12 @@ func (amw *jwtMiddleware) claimsToContext(ctx context.Context, claims *JWTClaims
|
|||
func invalidAuthResponse(w http.ResponseWriter) {
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
w.Header().Add("Content-Type", "application/json")
|
||||
json.NewEncoder(w).Encode(
|
||||
if err := json.NewEncoder(w).Encode(
|
||||
apiParams.APIErrorResponse{
|
||||
Error: "Authentication failed",
|
||||
})
|
||||
}); err != nil {
|
||||
log.Printf("failed to encode response: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
// Middleware implements the middleware interface
|
||||
|
|
@ -126,7 +128,6 @@ func (amw *jwtMiddleware) Middleware(next http.Handler) http.Handler {
|
|||
return
|
||||
}
|
||||
|
||||
ctx = SetJWTClaim(ctx, *claims)
|
||||
next.ServeHTTP(w, r.WithContext(ctx))
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -139,8 +139,8 @@ func init() {
|
|||
enterpriseAddCmd.Flags().StringVar(&enterpriseName, "name", "", "The name of the enterprise")
|
||||
enterpriseAddCmd.Flags().StringVar(&enterpriseWebhookSecret, "webhook-secret", "", "The webhook secret for this enterprise")
|
||||
enterpriseAddCmd.Flags().StringVar(&enterpriseCreds, "credentials", "", "Credentials name. See credentials list.")
|
||||
enterpriseAddCmd.MarkFlagRequired("credentials")
|
||||
enterpriseAddCmd.MarkFlagRequired("name")
|
||||
enterpriseAddCmd.MarkFlagRequired("credentials") //nolint
|
||||
enterpriseAddCmd.MarkFlagRequired("name") //nolint
|
||||
|
||||
enterpriseCmd.AddCommand(
|
||||
enterpriseListCmd,
|
||||
|
|
|
|||
|
|
@ -128,8 +128,8 @@ func init() {
|
|||
initCmd.Flags().StringVarP(&loginEmail, "email", "e", "", "Email address")
|
||||
initCmd.Flags().StringVarP(&loginFullName, "full-name", "f", "", "Full name of the user")
|
||||
initCmd.Flags().StringVarP(&loginPassword, "password", "p", "", "The admin password")
|
||||
initCmd.MarkFlagRequired("name")
|
||||
initCmd.MarkFlagRequired("url")
|
||||
initCmd.MarkFlagRequired("name") //nolint
|
||||
initCmd.MarkFlagRequired("url") //nolint
|
||||
}
|
||||
|
||||
func renderUserTable(user params.User) {
|
||||
|
|
|
|||
|
|
@ -238,10 +238,10 @@ func init() {
|
|||
orgPoolAddCmd.Flags().UintVar(&poolMaxRunners, "max-runners", 5, "The maximum number of runner this pool will create.")
|
||||
orgPoolAddCmd.Flags().UintVar(&poolMinIdleRunners, "min-idle-runners", 1, "Attempt to maintain a minimum of idle self-hosted runners of this type.")
|
||||
orgPoolAddCmd.Flags().BoolVar(&poolEnabled, "enabled", false, "Enable this pool.")
|
||||
orgPoolAddCmd.MarkFlagRequired("provider-name")
|
||||
orgPoolAddCmd.MarkFlagRequired("image")
|
||||
orgPoolAddCmd.MarkFlagRequired("flavor")
|
||||
orgPoolAddCmd.MarkFlagRequired("tags")
|
||||
orgPoolAddCmd.MarkFlagRequired("provider-name") //nolint
|
||||
orgPoolAddCmd.MarkFlagRequired("image") //nolint
|
||||
orgPoolAddCmd.MarkFlagRequired("flavor") //nolint
|
||||
orgPoolAddCmd.MarkFlagRequired("tags") //nolint
|
||||
|
||||
orgPoolUpdateCmd.Flags().StringVar(&poolImage, "image", "", "The provider-specific image name to use for runners in this pool.")
|
||||
orgPoolUpdateCmd.Flags().StringVar(&poolFlavor, "flavor", "", "The flavor to use for this runner.")
|
||||
|
|
|
|||
|
|
@ -139,8 +139,8 @@ func init() {
|
|||
orgAddCmd.Flags().StringVar(&orgName, "name", "", "The name of the organization")
|
||||
orgAddCmd.Flags().StringVar(&orgWebhookSecret, "webhook-secret", "", "The webhook secret for this organization")
|
||||
orgAddCmd.Flags().StringVar(&orgCreds, "credentials", "", "Credentials name. See credentials list.")
|
||||
orgAddCmd.MarkFlagRequired("credentials")
|
||||
orgAddCmd.MarkFlagRequired("name")
|
||||
orgAddCmd.MarkFlagRequired("credentials") //nolint
|
||||
orgAddCmd.MarkFlagRequired("name") //nolint
|
||||
|
||||
organizationCmd.AddCommand(
|
||||
orgListCmd,
|
||||
|
|
|
|||
|
|
@ -85,11 +85,11 @@ Example:
|
|||
} else if cmd.Flags().Changed("all") {
|
||||
pools, err = cli.ListAllPools()
|
||||
} else {
|
||||
cmd.Help()
|
||||
cmd.Help() //nolint
|
||||
os.Exit(0)
|
||||
}
|
||||
default:
|
||||
cmd.Help()
|
||||
cmd.Help() //nolint
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
|
|
@ -195,7 +195,7 @@ var poolAddCmd = &cobra.Command{
|
|||
} else if cmd.Flags().Changed("enterprise") {
|
||||
pool, err = cli.CreateEnterprisePool(poolEnterprise, newPoolParams)
|
||||
} else {
|
||||
cmd.Help()
|
||||
cmd.Help() //nolint
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
|
|
@ -313,10 +313,10 @@ func init() {
|
|||
poolAddCmd.Flags().UintVar(&poolRunnerBootstrapTimeout, "runner-bootstrap-timeout", 20, "Duration in minutes after which a runner is considered failed if it does not join Github.")
|
||||
poolAddCmd.Flags().UintVar(&poolMinIdleRunners, "min-idle-runners", 1, "Attempt to maintain a minimum of idle self-hosted runners of this type.")
|
||||
poolAddCmd.Flags().BoolVar(&poolEnabled, "enabled", false, "Enable this pool.")
|
||||
poolAddCmd.MarkFlagRequired("provider-name")
|
||||
poolAddCmd.MarkFlagRequired("image")
|
||||
poolAddCmd.MarkFlagRequired("flavor")
|
||||
poolAddCmd.MarkFlagRequired("tags")
|
||||
poolAddCmd.MarkFlagRequired("provider-name") //nolint
|
||||
poolAddCmd.MarkFlagRequired("image") //nolint
|
||||
poolAddCmd.MarkFlagRequired("flavor") //nolint
|
||||
poolAddCmd.MarkFlagRequired("tags") //nolint
|
||||
|
||||
poolAddCmd.Flags().StringVarP(&poolRepository, "repo", "r", "", "Add the new pool within this repository.")
|
||||
poolAddCmd.Flags().StringVarP(&poolOrganization, "org", "o", "", "Add the new pool withing this organization.")
|
||||
|
|
|
|||
|
|
@ -218,8 +218,8 @@ func init() {
|
|||
profileAddCmd.Flags().StringVarP(&loginURL, "url", "a", "", "The base URL for the runner manager API")
|
||||
profileAddCmd.Flags().StringVarP(&loginUserName, "username", "u", "", "Username to log in as")
|
||||
profileAddCmd.Flags().StringVarP(&loginPassword, "password", "p", "", "The user passowrd")
|
||||
profileAddCmd.MarkFlagRequired("name")
|
||||
profileAddCmd.MarkFlagRequired("url")
|
||||
profileAddCmd.MarkFlagRequired("name") //nolint
|
||||
profileAddCmd.MarkFlagRequired("url") //nolint
|
||||
|
||||
profileCmd.AddCommand(
|
||||
profileListCmd,
|
||||
|
|
|
|||
|
|
@ -225,10 +225,10 @@ func init() {
|
|||
repoPoolAddCmd.Flags().UintVar(&poolMaxRunners, "max-runners", 5, "The maximum number of runner this pool will create.")
|
||||
repoPoolAddCmd.Flags().UintVar(&poolMinIdleRunners, "min-idle-runners", 1, "Attempt to maintain a minimum of idle self-hosted runners of this type.")
|
||||
repoPoolAddCmd.Flags().BoolVar(&poolEnabled, "enabled", false, "Enable this pool.")
|
||||
repoPoolAddCmd.MarkFlagRequired("provider-name")
|
||||
repoPoolAddCmd.MarkFlagRequired("image")
|
||||
repoPoolAddCmd.MarkFlagRequired("flavor")
|
||||
repoPoolAddCmd.MarkFlagRequired("tags")
|
||||
repoPoolAddCmd.MarkFlagRequired("provider-name") //nolint
|
||||
repoPoolAddCmd.MarkFlagRequired("image") //nolint
|
||||
repoPoolAddCmd.MarkFlagRequired("flavor") //nolint
|
||||
repoPoolAddCmd.MarkFlagRequired("tags") //nolint
|
||||
|
||||
repoPoolUpdateCmd.Flags().StringVar(&poolImage, "image", "", "The provider-specific image name to use for runners in this pool.")
|
||||
repoPoolUpdateCmd.Flags().StringVar(&poolFlavor, "flavor", "", "The flavor to use for this runner.")
|
||||
|
|
|
|||
|
|
@ -142,9 +142,9 @@ func init() {
|
|||
repoAddCmd.Flags().StringVar(&repoName, "name", "", "The name of the repository")
|
||||
repoAddCmd.Flags().StringVar(&repoWebhookSecret, "webhook-secret", "", "The webhook secret for this repository")
|
||||
repoAddCmd.Flags().StringVar(&repoCreds, "credentials", "", "Credentials name. See credentials list.")
|
||||
repoAddCmd.MarkFlagRequired("credentials")
|
||||
repoAddCmd.MarkFlagRequired("owner")
|
||||
repoAddCmd.MarkFlagRequired("name")
|
||||
repoAddCmd.MarkFlagRequired("credentials") //nolint
|
||||
repoAddCmd.MarkFlagRequired("owner") //nolint
|
||||
repoAddCmd.MarkFlagRequired("name") //nolint
|
||||
|
||||
repositoryCmd.AddCommand(
|
||||
repoListCmd,
|
||||
|
|
|
|||
|
|
@ -98,11 +98,11 @@ Example:
|
|||
} else if cmd.Flags().Changed("all") {
|
||||
instances, err = cli.ListAllInstances()
|
||||
} else {
|
||||
cmd.Help()
|
||||
cmd.Help() //nolint
|
||||
os.Exit(0)
|
||||
}
|
||||
default:
|
||||
cmd.Help()
|
||||
cmd.Help() //nolint
|
||||
os.Exit(0)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -162,7 +162,7 @@ func (c *Config) SaveConfig() error {
|
|||
}
|
||||
cfgHandle, err := os.Create(cfgFile)
|
||||
if err != nil {
|
||||
errors.Wrap(err, "getting file handle")
|
||||
return errors.Wrap(err, "getting file handle")
|
||||
}
|
||||
|
||||
encoder := toml.NewEncoder(cfgHandle)
|
||||
|
|
|
|||
|
|
@ -86,8 +86,10 @@ func main() {
|
|||
var hub *websocket.Hub
|
||||
if cfg.Default.EnableLogStreamer {
|
||||
hub = websocket.NewHub(ctx)
|
||||
hub.Start()
|
||||
defer hub.Stop()
|
||||
if err := hub.Start(); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
defer hub.Stop() //nolint
|
||||
writers = append(writers, hub)
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -45,7 +45,9 @@ func (r *Runner) CreateEnterprise(ctx context.Context, param params.CreateEnterp
|
|||
|
||||
defer func() {
|
||||
if err != nil {
|
||||
r.store.DeleteEnterprise(ctx, enterprise.ID)
|
||||
if deleteErr := r.store.DeleteEnterprise(ctx, enterprise.ID); deleteErr != nil {
|
||||
log.Printf("failed to delete enterprise: %s", deleteErr)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
|
|||
|
|
@ -59,7 +59,9 @@ func (r *Runner) CreateOrganization(ctx context.Context, param params.CreateOrgP
|
|||
|
||||
defer func() {
|
||||
if err != nil {
|
||||
r.store.DeleteOrganization(ctx, org.ID)
|
||||
if deleteErr := r.store.DeleteOrganization(ctx, org.ID); deleteErr != nil {
|
||||
log.Printf("failed to delete org: %s", deleteErr)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
|
|||
|
|
@ -1009,7 +1009,7 @@ func (r *basePoolManager) deletePendingInstances() {
|
|||
return errors.Wrap(err, "deleting instance from database")
|
||||
}
|
||||
return
|
||||
}(instance)
|
||||
}(instance) //nolint
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -18,7 +18,6 @@ import (
|
|||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"log"
|
||||
"net"
|
||||
"net/http"
|
||||
|
|
@ -128,28 +127,28 @@ func getClientFromConfig(ctx context.Context, cfg *config.LXD) (cli lxd.Instance
|
|||
var srvCrtContents, tlsCAContents, clientCertContents, clientKeyContents []byte
|
||||
|
||||
if cfg.TLSServerCert != "" {
|
||||
srvCrtContents, err = ioutil.ReadFile(cfg.TLSServerCert)
|
||||
srvCrtContents, err = os.ReadFile(cfg.TLSServerCert)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "reading TLSServerCert")
|
||||
}
|
||||
}
|
||||
|
||||
if cfg.TLSCA != "" {
|
||||
tlsCAContents, err = ioutil.ReadFile(cfg.TLSCA)
|
||||
tlsCAContents, err = os.ReadFile(cfg.TLSCA)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "reading TLSCA")
|
||||
}
|
||||
}
|
||||
|
||||
if cfg.ClientCertificate != "" {
|
||||
clientCertContents, err = ioutil.ReadFile(cfg.ClientCertificate)
|
||||
clientCertContents, err = os.ReadFile(cfg.ClientCertificate)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "reading ClientCertificate")
|
||||
}
|
||||
}
|
||||
|
||||
if cfg.ClientKey != "" {
|
||||
clientKeyContents, err = ioutil.ReadFile(cfg.ClientKey)
|
||||
clientKeyContents, err = os.ReadFile(cfg.ClientKey)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "reading ClientKey")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -59,7 +59,9 @@ func (r *Runner) CreateRepository(ctx context.Context, param params.CreateRepoPa
|
|||
|
||||
defer func() {
|
||||
if err != nil {
|
||||
r.store.DeleteRepository(ctx, repo.ID)
|
||||
if deleteErr := r.store.DeleteRepository(ctx, repo.ID); deleteErr != nil {
|
||||
log.Printf("failed to delete repository: %s", deleteErr)
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
|
|
|
|||
|
|
@ -8,9 +8,5 @@ import (
|
|||
)
|
||||
|
||||
func IsExecutable(path string) bool {
|
||||
if unix.Access(path, unix.X_OK) == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
return false
|
||||
return unix.Access(path, unix.X_OK) == nil
|
||||
}
|
||||
|
|
|
|||
|
|
@ -55,8 +55,15 @@ func (c *Client) clientReader() {
|
|||
c.conn.Close()
|
||||
}()
|
||||
c.conn.SetReadLimit(maxMessageSize)
|
||||
c.conn.SetReadDeadline(time.Now().Add(pongWait))
|
||||
c.conn.SetPongHandler(func(string) error { c.conn.SetReadDeadline(time.Now().Add(pongWait)); return nil })
|
||||
if err := c.conn.SetReadDeadline(time.Now().Add(pongWait)); err != nil {
|
||||
log.Printf("failed to set read deadline: %s", err)
|
||||
}
|
||||
c.conn.SetPongHandler(func(string) error {
|
||||
if err := c.conn.SetReadDeadline(time.Now().Add(pongWait)); err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
for {
|
||||
mt, _, err := c.conn.ReadMessage()
|
||||
if err != nil {
|
||||
|
|
@ -78,10 +85,14 @@ func (c *Client) clientWriter() {
|
|||
for {
|
||||
select {
|
||||
case message, ok := <-c.send:
|
||||
c.conn.SetWriteDeadline(time.Now().Add(writeWait))
|
||||
if err := c.conn.SetWriteDeadline(time.Now().Add(writeWait)); err != nil {
|
||||
log.Printf("failed to set write deadline: %s", err)
|
||||
}
|
||||
if !ok {
|
||||
// The hub closed the channel.
|
||||
c.conn.WriteMessage(websocket.CloseMessage, []byte{})
|
||||
if err := c.conn.WriteMessage(websocket.CloseMessage, []byte{}); err != nil {
|
||||
log.Printf("failed to write message: %s", err)
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -90,7 +101,9 @@ func (c *Client) clientWriter() {
|
|||
return
|
||||
}
|
||||
case <-ticker.C:
|
||||
c.conn.SetWriteDeadline(time.Now().Add(writeWait))
|
||||
if err := c.conn.SetWriteDeadline(time.Now().Add(writeWait)); err != nil {
|
||||
log.Printf("failed to set write deadline: %s", err)
|
||||
}
|
||||
if err := c.conn.WriteMessage(websocket.PingMessage, nil); err != nil {
|
||||
return
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue