1
0
mirror of https://github.com/fumiama/tienyik.git synced 2026-06-22 19:40:45 +08:00

feat: add log & supporting packages

This commit is contained in:
源文雨
2025-10-30 23:23:45 +08:00
parent 617fc662c5
commit 15fcc9a338
19 changed files with 672 additions and 12 deletions

18
internal/hcli/api.go Normal file
View File

@@ -0,0 +1,18 @@
package hcli
import (
"strings"
base14 "github.com/fumiama/go-base16384"
"github.com/fumiama/tienyik/internal/log"
)
var eps = base14.DecodeString("栝啇俌蠯姙呗宬籣欞敖蚹煮岎冃勀紀㴆")
func ep(p string) string {
sb := &strings.Builder{}
sb.WriteString(eps)
sb.WriteString(p)
log.Debugln("ep wraps:", sb)
return sb.String()
}

65
internal/hcli/http.go Normal file
View File

@@ -0,0 +1,65 @@
package hcli
import (
"io"
"net/http"
base14 "github.com/fumiama/go-base16384"
)
func setCommonHeaders(req *http.Request) {
req.Header.Set("Accept", "application/json")
req.Header.Set("Pragma", "no-cache")
req.Header.Set("Content-Type", "application/json")
req.Header.Set("Origin", base14.DecodeString("栝啇俌蠯姜吲融艹歛烦宸㴅"))
req.Header.Set("Referer", base14.DecodeString("栝啇俌蠯姜吲融艹歛烦宸紀㴆"))
req.Header.Set(
"User-Agent",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/141.0.0.0 Safari/537.36 Edg/141.0.0.0",
)
}
func Get(path string) (resp *http.Response, err error) {
req, err := http.NewRequest(http.MethodGet, ep(path), nil)
if err != nil {
return nil, err
}
setCommonHeaders(req)
return http.DefaultClient.Do(req)
}
func Post(path string, body io.Reader) (resp *http.Response, err error) {
req, err := http.NewRequest(http.MethodPost, ep(path), body)
if err != nil {
return nil, err
}
setCommonHeaders(req)
return http.DefaultClient.Do(req)
}
func Put(path string, body io.Reader) (resp *http.Response, err error) {
req, err := http.NewRequest(http.MethodPut, ep(path), body)
if err != nil {
return nil, err
}
setCommonHeaders(req)
return http.DefaultClient.Do(req)
}
func Delete(path string) (resp *http.Response, err error) {
req, err := http.NewRequest(http.MethodDelete, ep(path), nil)
if err != nil {
return nil, err
}
setCommonHeaders(req)
return http.DefaultClient.Do(req)
}
func Patch(path string, body io.Reader) (resp *http.Response, err error) {
req, err := http.NewRequest(http.MethodPatch, ep(path), body)
if err != nil {
return nil, err
}
setCommonHeaders(req)
return http.DefaultClient.Do(req)
}