-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathconfig.go
More file actions
88 lines (73 loc) · 1.8 KB
/
config.go
File metadata and controls
88 lines (73 loc) · 1.8 KB
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package gospice
import (
"fmt"
"os"
"runtime"
"strings"
)
const GO_SPICE_VERSION = "8.0.0"
type ClientConfig struct {
HttpUrl string `json:"http_url,omitempty"`
FlightUrl string `json:"flight_url,omitempty"`
}
func LoadConfig() ClientConfig {
return ClientConfig{
HttpUrl: getEnvOrDefault("SPICE_HTTP_URL", "https://data.spiceai.io"),
FlightUrl: getEnvOrDefault("SPICE_FLIGHT_URL", "flight.spiceai.io:443"),
}
}
func LoadLocalConfig() ClientConfig {
return ClientConfig{
HttpUrl: getEnvOrDefault("SPICE_LOCAL_HTTP_URL", "http://127.0.0.1:8090"),
FlightUrl: getEnvOrDefault("SPICE_LOCAL_FLIGHT_URL", "grpc://127.0.0.1:50051"),
}
}
func getEnvOrDefault(key string, defaultValue string) string {
if v, exists := os.LookupEnv(key); exists {
return v
}
return defaultValue
}
func GetSpiceUserAgent() string {
// get OS type, release and machine type
// get Go version for SDK version
osType := runtime.GOOS
switch osType {
case "darwin":
osType = "Darwin"
case "linux":
osType = "Linux"
case "windows":
osType = "Windows"
case "freebsd":
osType = "FreeBSD"
case "openbsd":
osType = "OpenBSD"
case "android":
osType = "Android"
case "ios":
osType = "iOS"
}
osMachine := runtime.GOARCH
switch osMachine {
case "amd64":
osMachine = "x86_64"
case "386":
osMachine = "i386"
case "arm64":
osMachine = "aarch64"
}
osVersion := GetOSRelease()
userAgent := fmt.Sprintf("gospice/%s (%s/%s %s)", GO_SPICE_VERSION, osType, osVersion, osMachine)
// strip any non-printable ASCII characters
return RemoveNonPrintableASCII(userAgent)
}
func RemoveNonPrintableASCII(str string) string {
var builder strings.Builder
for _, ch := range str {
if ch >= 32 && ch <= 126 { // printable ASCII characters range from 32 to 126
builder.WriteRune(ch)
}
}
return builder.String()
}