github.com/easysoft/zendata@v0.0.0-20240513203326-705bd5a7fd67/internal/server/utils/gen.go (about) 1 package serverUtils 2 3 import ( 4 "net/http" 5 "strconv" 6 "strings" 7 8 consts "github.com/easysoft/zendata/internal/pkg/const" 9 ) 10 11 func ParseGenParams(req *http.Request) (defaultFile, configFile, fields string, count int, 12 format string, trim bool, table string, decode bool, input, output string) { 13 query := req.URL.Query() 14 15 defaultFile = ParserGetParams(query, "default", "d") 16 configFile = ParserGetParams(query, "config", "c") 17 trimStr := ParserGetParams(query, "trim", "T") 18 countStr := ParserGetParams(query, "lines", "n") 19 if countStr == "" { 20 countStr = "10" 21 } 22 23 fields = ParserGetParams(query, "field", "F") 24 25 format = consts.FormatJson 26 table = "" 27 28 trimStr = strings.ToLower(strings.TrimSpace(trimStr)) 29 if trimStr == "t" || trimStr == "true" { 30 trim = true 31 } 32 33 countFromForm, err := strconv.Atoi(countStr) 34 if err == nil { 35 count = countFromForm 36 } 37 38 return 39 } 40 41 func ParseGenParamsToByte(req *http.Request) (defaultDefContent, configDefContent []byte, fields string, count int, 42 format string, trim bool, table string, decode bool, input, output string) { 43 44 format = consts.FormatJson 45 table = "" 46 req.ParseForm() 47 48 defaultDefContent = []byte(ParserPostParams(req, "default", "d", "", true)) 49 configDefContent = []byte(ParserPostParams(req, "config", "c", "", true)) 50 trimStr := ParserPostParams(req, "trim", "T", "", false) 51 countStr := ParserPostParams(req, "lines", "n", "", false) 52 53 if countStr == "" { 54 countStr = "10" 55 } 56 57 trimStr = strings.ToLower(strings.TrimSpace(trimStr)) 58 if trimStr == "t" || trimStr == "true" { 59 trim = true 60 } 61 62 countFromForm, err := strconv.Atoi(countStr) 63 if err == nil { 64 count = countFromForm 65 } 66 67 return 68 }