-
Notifications
You must be signed in to change notification settings - Fork 0
/
serviceManifest.go
75 lines (58 loc) · 1.99 KB
/
serviceManifest.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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/*
ESRI REST API implementation library.
ServiceManifest function.
iteminfo and manifest give more info on a service
call example:
https://geo.geomsf.org/server/admin/services/wrl/wrl_ref_ppl.MapServer/iteminfo?f=pjson
https://geo.geomsf.org/server/admin/services/wrl/wrl_ref_ppl.MapServer/iteminfo/manifest/manifest.json?f=pjson
*/
package go_esri
import (
"encoding/json"
"net/url"
"github.com/go-resty/resty/v2"
)
type sdataBases struct {
ByReference bool `json:"byReference"`
OnServerWorkspaceFactoryProgID string `json:"onServerWorkspaceFactoryProgID"`
OnServerConnectionString string `json:"onServerConnectionString"`
OnPremiseConnectionString string `json:"onPremiseConnectionString"`
OnServerName string `json:"onServerName"`
OnPremisePath string `json:"onPremisePath"`
}
// struct returned by services call
type manifestJSON struct {
DataBases []sdataBases `json:"databases"`
}
// Returns DetailsJSON struct with service info
func ServiceManifest(token, serverName, folder, serviceFullName string) (*manifestJSON, error) {
// ----------------------------------------- build and validate url
baseUrl, err := url.Parse(serverName)
if err != nil {
return nil, err
}
baseUrl.Path += "/admin/services/"
baseUrl.Path += folder + "/"
baseUrl.Path += serviceFullName + "/"
baseUrl.Path += "iteminfo/manifest/manifest.json"
// ----------------------------------------- build url encode string to be included in the header body
v := url.Values{}
v.Set("token", token)
v.Add("f", "json")
// ----------------------------------------- request
req := resty.New()
resp, err := req.R().
SetHeader("Content-type", "application/x-www-form-urlencoded").
SetBody(string(v.Encode())).
Post(baseUrl.String())
if err != nil {
return nil, err
}
// ----------------------------------------- decode json response
var obj manifestJSON
err = json.Unmarshal(resp.Body(), &obj)
if err != nil {
return nil, err
}
return &obj, nil
}