commit ef324e3ae8fba7865cee1132e891533cbcfa366c
parent 07892f9a3d8da1ff3f86d737f6b47e81d49bc454
Author: Martin Schanzenbach <schanzen@gnunet.org>
Date: Thu, 24 Apr 2025 13:56:36 +0200
fix warnings
Diffstat:
1 file changed, 16 insertions(+), 20 deletions(-)
diff --git a/pkg/rest/gnsregistrar.go b/pkg/rest/gnsregistrar.go
@@ -225,7 +225,7 @@ func generateRegistrationId() string {
func (t *Registrar) landingPage(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "text/html; charset=utf-8")
- fullData := map[string]interface{}{
+ fullData := map[string]any{
"suffixHint": t.SuffixHint,
"extZkey": r.URL.Query().Get("zkey"),
"zoneKey": t.RootZoneKey,
@@ -236,32 +236,30 @@ func (t *Registrar) landingPage(w http.ResponseWriter, r *http.Request) {
if err != nil {
fmt.Println(err)
}
- return
}
func (t *Registrar) isNameValid(label string) (err error) {
- if "@" == label {
- return errors.New(fmt.Sprintf("'%s' invalid: '@' not allowed", label))
+ if label == "@" {
+ return fmt.Errorf("'%s' invalid: '@' not allowed", label)
}
if strings.Contains(label, ".") {
- return errors.New(fmt.Sprintf("'%s' invalid: '.' not allowed", label))
+ return fmt.Errorf("'%s' invalid: '.' not allowed", label)
}
if t.ValidLabelRegex != "" {
matched, _ := regexp.MatchString(t.ValidLabelRegex, label)
if !matched {
- return errors.New(fmt.Sprintf("Label '%s' not allowed by policy", label))
+ return fmt.Errorf("label '%s' not allowed by policy", label)
}
}
if t.ValidLabelScript != "" {
path, err := exec.LookPath(t.ValidLabelScript)
if err != nil {
fmt.Println(err)
- return errors.New(fmt.Sprintf("Internal error"))
+ return errors.New("internal error")
}
- out, err := exec.Command(path, label).Output()
+ _, err = exec.Command(path, label).Output()
if err != nil {
- fmt.Printf("%s, %w", out, err)
- return errors.New(fmt.Sprintf("Label '%s' not allowed by policy", label))
+ return fmt.Errorf("label '%s' not allowed by policy", label)
}
}
return
@@ -281,12 +279,11 @@ func (t *Registrar) searchPage(w http.ResponseWriter, r *http.Request) {
return
}
zkey = r.URL.Query().Get("zkey")
- if "" == zkey {
+ if zkey == "" {
http.Redirect(w, r, "/name/"+url.QueryEscape(label), http.StatusSeeOther)
} else {
http.Redirect(w, r, "/name/"+url.QueryEscape(label)+"?zkey="+url.QueryEscape(zkey), http.StatusSeeOther)
}
- return
}
func (t *Registrar) expireRegistration(label string) (err error) {
@@ -312,7 +309,7 @@ func (t *Registrar) expireRegistration(label string) (err error) {
}
if http.StatusNoContent != resp.StatusCode {
fmt.Printf("Got error: %d\n", resp.StatusCode)
- err = json.NewDecoder(resp.Body).Decode(&gnunetError)
+ _ = json.NewDecoder(resp.Body).Decode(&gnunetError)
return errors.New("GNUnet REST API error: " + gnunetError.Description)
}
return nil
@@ -469,7 +466,6 @@ func (t *Registrar) updateRegistration(w http.ResponseWriter, r *http.Request) {
return
}
http.Redirect(w, r, "/name/"+sanitizedLabel+"/edit?token="+token, http.StatusSeeOther)
- return
}
func (t *Registrar) editRegistration(w http.ResponseWriter, r *http.Request) {
@@ -539,7 +535,7 @@ func (t *Registrar) editRegistration(w http.ResponseWriter, r *http.Request) {
remainingDays := int64(time.Until(registeredUntil).Hours() / 24)
extendedExpiration := time.UnixMicro(int64(regMetadata.Expiration)).Add(t.RelativeRegistrationExpiration).Format(time.DateTime)
cost, _ := t.RegistrationCost.FormatWithCurrencySpecification(t.CurrencySpec)
- fullData := map[string]interface{}{
+ fullData := map[string]any{
"label": vars["label"],
"zkey": value,
"extendedExpiration": extendedExpiration,
@@ -556,7 +552,6 @@ func (t *Registrar) editRegistration(w http.ResponseWriter, r *http.Request) {
if err != nil {
fmt.Println(err)
}
- return
}
func (t *Registrar) paymentPage(w http.ResponseWriter, r *http.Request) {
@@ -651,7 +646,6 @@ func (t *Registrar) paymentPage(w http.ResponseWriter, r *http.Request) {
if err != nil {
fmt.Println(err)
}
- return
}
func (t *Registrar) buyPage(w http.ResponseWriter, r *http.Request) {
@@ -707,7 +701,7 @@ func (t *Registrar) buyPage(w http.ResponseWriter, r *http.Request) {
return
}
if nil != regMetadata {
- if regMetadata.Paid == false {
+ if !regMetadata.Paid {
http.Redirect(w, r, "/name/"+sanitizedLabel+"?error=Registration failed: Pending buy order", http.StatusSeeOther)
return
}
@@ -766,7 +760,6 @@ func (t *Registrar) buyPage(w http.ResponseWriter, r *http.Request) {
}
}
http.Redirect(w, r, "/name/"+sanitizedLabel+"/buy/payment?token="+regId, http.StatusSeeOther)
- return
}
func (t *Registrar) getCurrentRegistrationMetadata(label string, nsRecord *NamestoreRecord) (*RegistrationMetadata, error) {
@@ -959,7 +952,6 @@ func (t *Registrar) namePage(w http.ResponseWriter, r *http.Request) {
if err != nil {
fmt.Println(err)
}
- return
}
func (t *Registrar) setupHandlers() {
@@ -1037,6 +1029,10 @@ func (t *Registrar) Initialize(cfgfile string, version string) {
t.PaymentExpiration, _ = time.ParseDuration(paymentExp)
costStr := t.Cfg.Section("gns-registrar").Key("registration_cost").MustString("KUDOS:0.3")
t.RegistrationCost, err = talerutil.ParseAmount(costStr)
+ if err != nil {
+ fmt.Printf("Error parsing amount %s: %s\n", costStr, err.Error())
+ os.Exit(1)
+ }
t.BaseUrl = t.Cfg.Section("gns-registrar").Key("base_url").MustString("http://localhost:11000")
t.SuffixHint = t.Cfg.Section("gns-registrar").Key("suffix_hint").MustString("example.alt")
t.SummaryTemplateString = t.Cfg.Section("gns-registrar").Key("order_summary_template").MustString("Registration of `${NAME}' at GNUnet FCFS registrar")