Files
ddns-go/web/return_json.go
jeessy2 63b510bef2 Login page (#1094)
* feat: Add a login page

* feat: Modify save rules, more secure

* remove remoteAddr == "localhost"

* "登录失败次数过多,请等待 %d 分钟后再试

* cookie remove secure

* set cookie expires time by `NotAllowWanAccess`

* prettier

* fix: rename

* feat: auto login if unfilled

* feat: auto login if there is no username/password

* auto login if no username/password
2024-04-26 19:35:08 -07:00

35 lines
619 B
Go

package web
import (
"encoding/json"
"net/http"
)
// Result Result
type Result struct {
Code int // 状态
Msg string // 消息
Data interface{} // 数据
}
// returnError 返回错误信息
func returnError(w http.ResponseWriter, msg string) {
result := &Result{}
result.Code = http.StatusInternalServerError
result.Msg = msg
json.NewEncoder(w).Encode(result)
}
// returnOK 返回成功信息
func returnOK(w http.ResponseWriter, msg string, data interface{}) {
result := &Result{}
result.Code = http.StatusOK
result.Msg = msg
result.Data = data
json.NewEncoder(w).Encode(result)
}