Browse Source

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

master
Jared 1 year ago
parent
commit
66a11e5085
2 changed files with 33 additions and 1 deletions
  1. +32
    -0
      endpoints/getusers.go
  2. +1
    -1
      main.go

+ 32
- 0
endpoints/getusers.go View File

@@ -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 View File

@@ -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)


Loading…
Cancel
Save