瀏覽代碼

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

master
Jared 1 年之前
父節點
當前提交
66a11e5085
共有 2 個檔案被更改,包括 33 行新增1 行删除
  1. +32
    -0
      endpoints/getusers.go
  2. +1
    -1
      main.go

+ 32
- 0
endpoints/getusers.go 查看文件

@@ -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 查看文件

@@ -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…
取消
儲存