mirror of
https://github.com/fumiama/tienyik.git
synced 2026-07-02 08:50:24 +08:00
feat: add more apis
This commit is contained in:
35
internal/horm/req.go
Normal file
35
internal/horm/req.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package horm
|
||||
|
||||
import (
|
||||
"net/url"
|
||||
"reflect"
|
||||
|
||||
"github.com/fumiama/tienyik"
|
||||
"github.com/fumiama/tienyik/internal/textio"
|
||||
)
|
||||
|
||||
func Marshal(tya *tienyik.AES, x any) []byte {
|
||||
q := url.Values{}
|
||||
v := reflect.ValueOf(x).Elem()
|
||||
t := v.Type()
|
||||
|
||||
for i := 0; i < v.NumField(); i++ {
|
||||
field := v.Field(i)
|
||||
fieldType := t.Field(i)
|
||||
|
||||
formTag := fieldType.Tag.Get("form")
|
||||
if formTag == "" || formTag == "-" {
|
||||
continue
|
||||
}
|
||||
|
||||
if field.Kind() == reflect.String {
|
||||
q.Set(formTag, field.String())
|
||||
}
|
||||
}
|
||||
|
||||
s := q.Encode()
|
||||
if tya != nil {
|
||||
return tya.Encrypt(textio.StringToBytes(s))
|
||||
}
|
||||
return textio.StringToBytes(s)
|
||||
}
|
||||
Reference in New Issue
Block a user