forked from hishamkaram/geoserver
-
Notifications
You must be signed in to change notification settings - Fork 0
/
geoserver.go
57 lines (50 loc) · 1.28 KB
/
geoserver.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
47
48
49
50
51
52
53
54
55
56
57
package geoserver
import (
"io"
"io/ioutil"
"net/http"
"github.com/sirupsen/logrus"
yaml "gopkg.in/yaml.v2"
)
//GeoServer is the configuration Object
type GeoServer struct {
WorkspaceName string `yaml:"workspace"`
ServerURL string `yaml:"geoserver_url"`
Username string `yaml:"username"`
Password string `yaml:"password"`
httpClient *http.Client
logger *logrus.Logger
}
//LoadConfig load geoserver config from yaml file
func (g *GeoServer) LoadConfig(configFile string) (geoserver *GeoServer, err error) {
yamlFile, err := ioutil.ReadFile(configFile)
if err != nil {
g.logger.Errorf("yamlFile.Get err %v ", err)
return
}
err = yaml.Unmarshal(yamlFile, g)
if err != nil {
g.logger.Errorf("Unmarshal: %v", err)
return
}
g.logger = GetLogger()
geoserver = g
return
}
// GetGeoserverRequest creates a HTTP request with geoserver credintails and header
func (g *GeoServer) GetGeoserverRequest(
targetURL string,
method string,
accept string,
data io.Reader,
contentType string) (request *http.Request) {
request, _ = http.NewRequest(method, targetURL, data)
if data != nil {
request.Header.Set(contentTypeHeader, contentType)
}
if accept != "" {
request.Header.Set(acceptHeader, accept)
}
request.SetBasicAuth(g.Username, g.Password)
return
}