app-init
This commit is contained in:
@@ -0,0 +1,63 @@
|
||||
package navicat
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// Request is one Navicat HTTP Tunnel POST body.
|
||||
type Request struct {
|
||||
Action string
|
||||
Host string
|
||||
Port int
|
||||
Login string
|
||||
Password string
|
||||
Database string
|
||||
Queries []string
|
||||
EncodeBase64 bool
|
||||
}
|
||||
|
||||
// Form builds application/x-www-form-urlencoded fields matching $_POST in ntunnel_mysql.php.
|
||||
func (r Request) Form() url.Values {
|
||||
v := url.Values{}
|
||||
v.Set("actn", r.Action)
|
||||
v.Set("host", r.Host)
|
||||
if r.Port > 0 {
|
||||
v.Set("port", strconv.Itoa(r.Port))
|
||||
} else {
|
||||
v.Set("port", "")
|
||||
}
|
||||
v.Set("login", r.Login)
|
||||
v.Set("password", r.Password)
|
||||
v.Set("db", r.Database)
|
||||
|
||||
queries := nonEmpty(r.Queries)
|
||||
if r.EncodeBase64 {
|
||||
v.Set("encodeBase64", "1")
|
||||
for _, q := range queries {
|
||||
v.Add("q[]", base64.StdEncoding.EncodeToString([]byte(q)))
|
||||
}
|
||||
} else {
|
||||
for _, q := range queries {
|
||||
v.Add("q[]", q)
|
||||
}
|
||||
}
|
||||
return v
|
||||
}
|
||||
|
||||
func (r Request) Encode() string {
|
||||
return r.Form().Encode()
|
||||
}
|
||||
|
||||
func nonEmpty(in []string) []string {
|
||||
out := make([]string, 0, len(in))
|
||||
for _, s := range in {
|
||||
if strings.TrimSpace(s) == "" {
|
||||
continue
|
||||
}
|
||||
out = append(out, s)
|
||||
}
|
||||
return out
|
||||
}
|
||||
Reference in New Issue
Block a user