mirror of
https://github.com/jeessy2/ddns-go.git
synced 2025-10-20 23:43:45 +08:00
* 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
35 lines
619 B
Go
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)
|
|
}
|