Parcourir la source

Add a new endpoint and remove an unused one from the router

master
Jared il y a 1 an
Parent
révision
66a11e5085
2 fichiers modifiés avec 33 ajouts et 1 suppressions
  1. +32
    -0
      endpoints/getusers.go
  2. +1
    -1
      main.go

+ 32
- 0
endpoints/getusers.go Voir le fichier

@@ -0,0 +1,32 @@
package endpoints

import (
"encoding/json"
"net/http"

"github.com/imosed/signet/auth"
. "github.com/imosed/signet/data"
)

type GetUsersResponse struct {
Users []User `json:"users"`
}

func GetUsers(w http.ResponseWriter, r *http.Request) {
claims, err := auth.GetUserClaims(r)

if claims.Privileges > AdminPlus {
return
}

var users []User
Db.Table("users").Scan(&users)

var resp GetUsersResponse
resp.Users = users

err = json.NewEncoder(w).Encode(resp)
if err != nil {
panic("Could not deliver response")
}
}

+ 1
- 1
main.go Voir le fichier

@@ -42,7 +42,7 @@ func main() {
router.HandleFunc("/CloseRewardFund", endpoints.CloseRewardFund)
router.HandleFunc("/SubmitRewardFund", endpoints.SubmitFund)
router.HandleFunc("/DistributeRewardFund", endpoints.DistributeRewards)
// router.HandleFunc("/SubmitFund", endpoints.SubmitFund)
router.HandleFunc("/GetUsers", endpoints.GetUsers)
router.HandleFunc("/GetBalance", endpoints.GetBalance)
router.HandleFunc("/Contribute", endpoints.Contribute)
router.HandleFunc("/ContributorStream", endpoints.ContributorStream)


Chargement…
Annuler
Enregistrer