aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Schanzenbach <schanzen@gnunet.org>2024-01-13 13:07:57 +0100
committerMartin Schanzenbach <schanzen@gnunet.org>2024-01-13 13:07:57 +0100
commitb155150004b3ae3bef58f6d3096f8c4d91d6a72e (patch)
treed378c74b5a29ce653344e7e8c2debbafa9e639d2
parent5ed1673d40847153e01d5c83efe6fc373d0062da (diff)
downloadgnunet-gns-registrar-b155150004b3ae3bef58f6d3096f8c4d91d6a72e.tar.gz
gnunet-gns-registrar-b155150004b3ae3bef58f6d3096f8c4d91d6a72e.zip
Make static analyzer happy
-rw-r--r--pkg/rest/gnsregistrar.go64
1 files changed, 52 insertions, 12 deletions
diff --git a/pkg/rest/gnsregistrar.go b/pkg/rest/gnsregistrar.go
index b119300..e36b302 100644
--- a/pkg/rest/gnsregistrar.go
+++ b/pkg/rest/gnsregistrar.go
@@ -208,7 +208,11 @@ func (t *Registrar) configResponse(w http.ResponseWriter, r *http.Request) {
208 Version: "0:0:0", 208 Version: "0:0:0",
209 } 209 }
210 w.Header().Set("Content-Type", "application/json") 210 w.Header().Set("Content-Type", "application/json")
211 response, _ := json.Marshal(cfg) 211 response, err := json.Marshal(cfg)
212 if nil != err {
213 fmt.Println(err)
214 return
215 }
212 w.Write(response) 216 w.Write(response)
213} 217}
214 218
@@ -224,7 +228,10 @@ func (t *Registrar) landingPage(w http.ResponseWriter, r *http.Request) {
224 "zoneKey": t.RootZoneKey, 228 "zoneKey": t.RootZoneKey,
225 "error": r.URL.Query().Get("error"), 229 "error": r.URL.Query().Get("error"),
226 } 230 }
227 t.LandingTpl.Execute(w, fullData) 231 err := t.LandingTpl.Execute(w, fullData)
232 if err != nil {
233 fmt.Println(err)
234 }
228 return 235 return
229} 236}
230 237
@@ -283,7 +290,10 @@ func (t *Registrar) expireRegistration(label string) (err error) {
283 req.SetBasicAuth(t.GnunetUsername, t.GnunetPassword) 290 req.SetBasicAuth(t.GnunetUsername, t.GnunetPassword)
284 } 291 }
285 resp, err := client.Do(req) 292 resp, err := client.Do(req)
286 resp.Body.Close() 293 if err != nil {
294 return err
295 }
296 err = resp.Body.Close()
287 if err != nil { 297 if err != nil {
288 return err 298 return err
289 } 299 }
@@ -310,7 +320,10 @@ func (t *Registrar) createOrUpdateRegistration(nsRecord *NamestoreRecord) (err e
310 if nil != err { 320 if nil != err {
311 return err 321 return err
312 } 322 }
313 resp.Body.Close() 323 err = resp.Body.Close()
324 if err != nil {
325 return err
326 }
314 if http.StatusNoContent != resp.StatusCode { 327 if http.StatusNoContent != resp.StatusCode {
315 fmt.Printf("Got error: %d\n", resp.StatusCode) 328 fmt.Printf("Got error: %d\n", resp.StatusCode)
316 err = json.NewDecoder(resp.Body).Decode(&gnunetError) 329 err = json.NewDecoder(resp.Body).Decode(&gnunetError)
@@ -416,7 +429,12 @@ func (t *Registrar) updateRegistration(w http.ResponseWriter, r *http.Request) {
416 http.Redirect(w, r, "/name/"+vars["label"], http.StatusSeeOther) 429 http.Redirect(w, r, "/name/"+vars["label"], http.StatusSeeOther)
417 return 430 return
418 } 431 }
419 r.ParseForm() 432 err = r.ParseForm()
433 if nil != err {
434 fmt.Printf("Unable to parse form: " + err.Error())
435 http.Redirect(w, r, "/name/"+vars["label"] + "?error=Form invalid", http.StatusSeeOther)
436 return
437 }
420 token = r.Form.Get("token") 438 token = r.Form.Get("token")
421 zkey = r.Form.Get("zkey") 439 zkey = r.Form.Get("zkey")
422 if regMetadata.RegistrationID != token { 440 if regMetadata.RegistrationID != token {
@@ -517,7 +535,10 @@ func (t *Registrar) editRegistration(w http.ResponseWriter, r *http.Request) {
517 "cost": cost, 535 "cost": cost,
518 "suffixHint": t.SuffixHint, 536 "suffixHint": t.SuffixHint,
519 } 537 }
520 t.EditTpl.Execute(w, fullData) 538 err = t.EditTpl.Execute(w, fullData)
539 if err != nil {
540 fmt.Println(err)
541 }
521 return 542 return
522} 543}
523 544
@@ -648,7 +669,10 @@ func (t *Registrar) buyPage(w http.ResponseWriter, r *http.Request) {
648 "cost": cost, 669 "cost": cost,
649 "suffixHint": t.SuffixHint, 670 "suffixHint": t.SuffixHint,
650 } 671 }
651 t.BuyTpl.Execute(w, fullData) 672 err = t.BuyTpl.Execute(w, fullData)
673 if err != nil {
674 fmt.Println(err)
675 }
652 return 676 return
653} 677}
654 678
@@ -678,7 +702,10 @@ func (t *Registrar) getCurrentRegistrationMetadata(label string, nsRecord *Names
678 if rc == http.StatusNotFound { 702 if rc == http.StatusNotFound {
679 if time.Now().After(time.UnixMicro(int64(regMetadata.Expiration))) { 703 if time.Now().After(time.UnixMicro(int64(regMetadata.Expiration))) {
680 fmt.Printf("Registration for %s not found, removing\n", label) 704 fmt.Printf("Registration for %s not found, removing\n", label)
681 t.expireRegistration(label) 705 err := t.expireRegistration(label)
706 if nil != err {
707 fmt.Println(err)
708 }
682 return nil, nil 709 return nil, nil
683 } else { 710 } else {
684 return &regMetadata, nil 711 return &regMetadata, nil
@@ -722,14 +749,20 @@ func (t *Registrar) getCurrentRegistrationMetadata(label string, nsRecord *Names
722 // Remove metadata if payment limit exceeded and registration expired 749 // Remove metadata if payment limit exceeded and registration expired
723 if time.Now().After(regMetadata.NeedsPaymentUntil) && time.Now().After(time.UnixMicro(int64(regMetadata.Expiration))) { 750 if time.Now().After(regMetadata.NeedsPaymentUntil) && time.Now().After(time.UnixMicro(int64(regMetadata.Expiration))) {
724 fmt.Printf("Payment request for %s has expired, removing\n", label) 751 fmt.Printf("Payment request for %s has expired, removing\n", label)
725 t.expireRegistration(label) 752 err := t.expireRegistration(label)
753 if nil != err {
754 fmt.Println(err)
755 }
726 return nil, nil 756 return nil, nil
727 } 757 }
728 } 758 }
729 } else { 759 } else {
730 if time.Now().After(time.UnixMicro(int64(regMetadata.Expiration))) { 760 if time.Now().After(time.UnixMicro(int64(regMetadata.Expiration))) {
731 fmt.Printf("Registration for %s has expired, removing\n", label) 761 fmt.Printf("Registration for %s has expired, removing\n", label)
732 t.expireRegistration(label) 762 err := t.expireRegistration(label)
763 if nil != err {
764 fmt.Println(err)
765 }
733 return nil, nil 766 return nil, nil
734 } 767 }
735 } 768 }
@@ -826,7 +859,10 @@ func (t *Registrar) namePage(w http.ResponseWriter, r *http.Request) {
826 "remainingDays": remainingDays, 859 "remainingDays": remainingDays,
827 "registrationSuccess": registered, 860 "registrationSuccess": registered,
828 } 861 }
829 t.NameTpl.Execute(w, fullData) 862 err = t.NameTpl.Execute(w, fullData)
863 if err != nil {
864 fmt.Println(err)
865 }
830 return 866 return
831} 867}
832 868
@@ -859,7 +895,11 @@ func (t *Registrar) Initialize(cfgfile string) {
859 fmt.Printf("Failed to read config: %v", err) 895 fmt.Printf("Failed to read config: %v", err)
860 os.Exit(1) 896 os.Exit(1)
861 } 897 }
862 _cfg.WriteTo(os.Stdout) 898 _, err = _cfg.WriteTo(os.Stdout)
899 if err != nil {
900 fmt.Println(err)
901 os.Exit(1)
902 }
863 t.Cfg = _cfg 903 t.Cfg = _cfg
864 if t.Cfg.Section("gns-registrar").Key("production").MustBool(false) { 904 if t.Cfg.Section("gns-registrar").Key("production").MustBool(false) {
865 fmt.Println("Production mode enabled") 905 fmt.Println("Production mode enabled")