Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
gitpod-io
GitHub Repository: gitpod-io/gitpod
Path: blob/main/components/ide-service-api/go/config/config.go
2500 views
1
// Copyright (c) 2022 Gitpod GmbH. All rights reserved.
2
// Licensed under the GNU Affero General Public License (AGPL).
3
// See License.AGPL.txt in the project root for license information.
4
5
package config
6
7
import (
8
"bytes"
9
"encoding/json"
10
"os"
11
12
"github.com/gitpod-io/gitpod/common-go/baseserver"
13
"golang.org/x/xerrors"
14
)
15
16
type ServiceConfiguration struct {
17
Server *baseserver.Configuration `json:"server,omitempty"`
18
IDEConfigPath string `json:"ideConfigPath"`
19
DockerCfg string `json:"dockerCfg"`
20
}
21
22
func Read(fn string) (*ServiceConfiguration, error) {
23
ctnt, err := os.ReadFile(fn)
24
if err != nil {
25
return nil, xerrors.Errorf("cannot read config file: %w", err)
26
}
27
28
var cfg ServiceConfiguration
29
dec := json.NewDecoder(bytes.NewReader(ctnt))
30
dec.DisallowUnknownFields()
31
err = dec.Decode(&cfg)
32
if err != nil {
33
return nil, xerrors.Errorf("cannot parse config file: %w", err)
34
}
35
36
return &cfg, nil
37
}
38
39