File: iface.go

package info (click to toggle)
golang-github-wenerme-astgo 0.0~git20230926.1b5bc38-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 612 kB
  • sloc: makefile: 16
file content (60 lines) | stat: -rw-r--r-- 962 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package agimodels

import (
	"fmt"
	"strconv"
	"strings"
)

type Command interface {
	Command() (string, error)
}
type Response interface {
	Err() error
	Val() (string, error)
}

type Handler interface {
	Command(cmd Command) Response
}
type HandlerFunc func(cmd Command) Response

func (f HandlerFunc) Command(cmd Command) Response {
	return f(cmd)
}

type Client struct {
	Handler
}

func joinCommand(s []interface{}) string {
	sb := strings.Builder{}
	for _, param := range s {
		switch v := param.(type) {
		case string:
			sb.WriteString(v)
		case int:
			sb.WriteString(strconv.Itoa(v))
		case float64:
			sb.WriteString(fmt.Sprint(v))
		case *string:
			if v == nil {
				goto DONE
			}
			sb.WriteString(*v)
		case *int:
			if v == nil {
				goto DONE
			}
			sb.WriteString(strconv.Itoa(*v))
		case *float64:
			if v == nil {
				goto DONE
			}
			sb.WriteString(fmt.Sprint(*v))
		}
		sb.WriteRune(' ')
	}
DONE:
	return strings.TrimSpace(sb.String())
}