| 1 | package agimodels |
| 2 | |
| 3 | import ( |
| 4 | "fmt" |
| 5 | "strconv" |
| 6 | "strings" |
| 7 | ) |
| 8 | |
| 9 | type Command interface { |
| 10 | Command() (string, error) |
| 11 | } |
| 12 | type Response interface { |
| 13 | Err() error |
| 14 | Val() (string, error) |
| 15 | } |
| 16 | |
| 17 | type Handler interface { |
| 18 | Command(cmd Command) Response |
| 19 | } |
| 20 | type HandlerFunc func(cmd Command) Response |
| 21 | |
| 22 | func (f HandlerFunc) Command(cmd Command) Response { |
| 23 | return f(cmd) |
| 24 | } |
| 25 | |
| 26 | type Client struct { |
| 27 | Handler |
| 28 | } |
| 29 | |
| 30 | func joinCommand(s []interface{}) string { |
| 31 | sb := strings.Builder{} |
| 32 | for _, param := range s { |
| 33 | switch v := param.(type) { |
| 34 | case string: |
| 35 | sb.WriteString(v) |
| 36 | case int: |
| 37 | sb.WriteString(strconv.Itoa(v)) |
| 38 | case float64: |
| 39 | sb.WriteString(fmt.Sprint(v)) |
| 40 | case *string: |
| 41 | if v == nil { |
| 42 | goto DONE |
| 43 | } |
| 44 | sb.WriteString(*v) |
| 45 | case *int: |
| 46 | if v == nil { |
| 47 | goto DONE |
| 48 | } |
| 49 | sb.WriteString(strconv.Itoa(*v)) |
| 50 | case *float64: |
| 51 | if v == nil { |
| 52 | goto DONE |
| 53 | } |
| 54 | sb.WriteString(fmt.Sprint(*v)) |
| 55 | } |
| 56 | sb.WriteRune(' ') |
| 57 | } |
| 58 | DONE: |
| 59 | return strings.TrimSpace(sb.String()) |
| 60 | } |