working sub

This commit is contained in:
2026-03-05 12:21:32 +03:00
parent 205d9cf8b0
commit 951f3ab482
6 changed files with 65 additions and 14 deletions

View File

@@ -14,6 +14,14 @@ import (
"github.com/go-chi/chi/v5"
)
func GetConfig(w http.ResponseWriter, _ *http.Request) {
res := map[string]any{
"config": cfg,
"hysteria": hysteriaCfg,
}
WriteResponse(w, res)
}
type AddUserReq struct {
Username string `json:"username"`
Password string `json:"password"`
@@ -84,6 +92,44 @@ func AllUsers(w http.ResponseWriter, r *http.Request) {
}
WriteResponse(w, users)
}
func GetUser(w http.ResponseWriter, r *http.Request) {
fmt.Println("GetUser called")
if !CheckToken(r) {
WriteError(w, errors.New("token required"))
return
}
id := chi.URLParam(r, "id")
userId, err := strconv.Atoi(id)
if err != nil {
WriteError(w, err)
return
}
rep := NewUserRepository(db)
user, err := rep.GetById(userId)
WriteResponseOrError(w, user, err)
}
func GetUserKey(w http.ResponseWriter, r *http.Request) {
fmt.Println("GetUserKey called")
if !CheckToken(r) {
WriteError(w, errors.New("token required"))
return
}
id := chi.URLParam(r, "id")
userId, err := strconv.Atoi(id)
if err != nil {
WriteError(w, err)
return
}
rep := NewUserRepository(db)
user, err := rep.GetById(userId)
if err != nil {
WriteError(w, err)
return
}
WriteResponse(w, encodeURL(user))
}
type GetConnectURLReq struct {
ID int `json:"id"`