-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgsConfig.go
46 lines (34 loc) · 985 Bytes
/
gsConfig.go
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
package main
import (
"encoding/json"
"io/ioutil"
"os"
"github.com/google/uuid"
)
type gsConfig struct {
Id uuid.UUID `json:"id"`
Type ConnectionType `json:"type"`
Topic string `json:"topic"`
}
type gsConsumerConfig struct {
gsConfig
StartTimestamp string `json:"startTimestamp"`
}
func (gsConfig) Create(connection_type ConnectionType, topic string) (gsConfig, error) {
id := uuid.New()
validation_err := failInvalidConnectionType(&connection_type)
if validation_err != nil {
return gsConfig{}, validation_err
}
return gsConfig{Id: id, Type: connection_type, Topic: topic}, nil
}
func (gsConfig) CreateFromFile(configFilePath string) (gsConfig, error) {
id := uuid.New()
file, err := os.Open(configFilePath)
checkError(err)
defer file.Close()
configBytes, _ := ioutil.ReadAll(file)
base_config := gsConfig{}
json.Unmarshal(configBytes, &base_config)
return gsConfig{Id: id, Type: base_config.Type, Topic: base_config.Topic}, nil
}