Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Go API matching GeoServer REST API #1

Merged
merged 11 commits into from Aug 11, 2022
16 changes: 14 additions & 2 deletions client/client.go
Expand Up @@ -28,12 +28,24 @@ func NewClient(url, username, password string) (client *Client, err error) {
}

func (c *Client) doRequest(method, path string, data io.Reader) (statusCode int, body string, err error) {
return c.doTypedRequest(method, path, data, "application/xml")
}

func (c *Client) doTypedRequest(method, path string, data io.Reader, contentType string) (statusCode int, body string, err error) {
return c.doFullyTypedRequest(method, path, data, contentType, contentType)
}

func (c *Client) doFullyTypedRequest(method, path string, data io.Reader, contentType string, acceptType string) (statusCode int, body string, err error) {
request, err := http.NewRequest(method, c.URL+path, data)
if err != nil {
return
}
request.Header.Set("Content-Type", "application/xml")
request.Header.Set("Accept", "application/xml")
if contentType != "" {
request.Header.Set("Content-Type", contentType)
}
if acceptType != "" {
request.Header.Set("Accept", acceptType)
}
if c.Username != "" && c.Password != "" {
request.SetBasicAuth(c.Username, c.Password)
}
Expand Down
2 changes: 1 addition & 1 deletion client/datastore.go
Expand Up @@ -6,7 +6,7 @@ import (
"fmt"
)

// DatastoreRef is a reference to a Datastore
// DatastoreReference is a reference to a Datastore
type DatastoreReference struct {
Name string `xml:"name"`
}
Expand Down
26 changes: 13 additions & 13 deletions client/datastore_test.go
Expand Up @@ -53,18 +53,18 @@ func TestGetDatastoresSuccess(t *testing.T) {
defer testServer.Close()

expectedResult := []*Datastore{
&Datastore{
{
XMLName: xml.Name{
Local: "dataStore",
},
Name: "sf",
Enabled: true,
ConnectionParameters: []*DatastoreConnectionParameter{
&DatastoreConnectionParameter{
{
Key: "url",
Value: "file:data/sf",
},
&DatastoreConnectionParameter{
{
Key: "namespace",
Value: "http://www.openplans.org/spearfish",
},
Expand Down Expand Up @@ -123,11 +123,11 @@ func TestGetDatastoreSuccess(t *testing.T) {
Name: "sf",
Enabled: true,
ConnectionParameters: []*DatastoreConnectionParameter{
&DatastoreConnectionParameter{
{
Key: "url",
Value: "file:data/sf",
},
&DatastoreConnectionParameter{
{
Key: "namespace",
Value: "http://www.openplans.org/spearfish",
},
Expand Down Expand Up @@ -229,11 +229,11 @@ func TestCreateDatastoreSuccess(t *testing.T) {
Name: "sf",
Enabled: true,
ConnectionParameters: []*DatastoreConnectionParameter{
&DatastoreConnectionParameter{
{
Key: "url",
Value: "file:data/sf",
},
&DatastoreConnectionParameter{
{
Key: "namespace",
Value: "http://www.openplans.org/spearfish",
},
Expand All @@ -254,11 +254,11 @@ func TestCreateDatastoreSuccess(t *testing.T) {
Name: "sf",
Enabled: true,
ConnectionParameters: []*DatastoreConnectionParameter{
&DatastoreConnectionParameter{
{
Key: "url",
Value: "file:data/sf",
},
&DatastoreConnectionParameter{
{
Key: "namespace",
Value: "http://www.openplans.org/spearfish",
},
Expand All @@ -285,11 +285,11 @@ func TestUpdateDatastoreSuccess(t *testing.T) {
Name: "sf",
Enabled: true,
ConnectionParameters: []*DatastoreConnectionParameter{
&DatastoreConnectionParameter{
{
Key: "url",
Value: "file:data/sf",
},
&DatastoreConnectionParameter{
{
Key: "namespace",
Value: "http://www.openplans.org/spearfish",
},
Expand All @@ -310,11 +310,11 @@ func TestUpdateDatastoreSuccess(t *testing.T) {
Name: "sf",
Enabled: true,
ConnectionParameters: []*DatastoreConnectionParameter{
&DatastoreConnectionParameter{
{
Key: "url",
Value: "file:data/sf",
},
&DatastoreConnectionParameter{
{
Key: "namespace",
Value: "http://www.openplans.org/spearfish",
},
Expand Down
2 changes: 2 additions & 0 deletions client/featuretype.go
Expand Up @@ -17,11 +17,13 @@ type FeatureTypeKeywords struct {
Keywords []string `xml:"string"`
}

// FeatureTypeCRS describes CRS information
type FeatureTypeCRS struct {
Class string `xml:"class,attr,omitempty"`
Value string `xml:",chardata"`
}

// FeatureTypes is a list of FeatureType
type FeatureTypes struct {
XMLName xml.Name `xml:"featureTypes"`
List []*FeatureType `xml:"featureType"`
Expand Down
52 changes: 26 additions & 26 deletions client/featuretype_test.go
Expand Up @@ -39,7 +39,7 @@ func TestGetFeatureTypesNoDatastoreSuccess(t *testing.T) {
defer testServer.Close()

expectedResult := []*FeatureType{
&FeatureType{
{
XMLName: xml.Name{
Space: "",
Local: "featureType",
Expand Down Expand Up @@ -88,7 +88,7 @@ func TestGetFeatureTypesInDatastoreSuccess(t *testing.T) {
defer testServer.Close()

expectedResult := []*FeatureType{
&FeatureType{
{
XMLName: xml.Name{
Local: "featureType",
},
Expand Down Expand Up @@ -241,17 +241,17 @@ func TestGetFeatureTypeNoDatastoreSuccess(t *testing.T) {
ProjectionPolicy: "NONE",
Enabled: true,
Metadata: []*FeatureTypeMetadata{
&FeatureTypeMetadata{
{
Key: "time",
Value: "<dimensionInfo><enabled>false</enabled><defaultValue/></dimensionInfo>",
},
&FeatureTypeMetadata{
{
Key: "cachingEnabled",
Value: "true",
},
},
Attributes: []*FeatureTypeAttribute{
&FeatureTypeAttribute{
{
Name: "the_geom",
MinOccurs: 0,
MaxOccurs: 1,
Expand Down Expand Up @@ -406,17 +406,17 @@ func TestGetFeatureTypeInDatastoreSuccess(t *testing.T) {
ProjectionPolicy: "NONE",
Enabled: true,
Metadata: []*FeatureTypeMetadata{
&FeatureTypeMetadata{
{
Key: "time",
Value: "<dimensionInfo><enabled>false</enabled><defaultValue/></dimensionInfo>",
},
&FeatureTypeMetadata{
{
Key: "cachingEnabled",
Value: "true",
},
},
Attributes: []*FeatureTypeAttribute{
&FeatureTypeAttribute{
{
Name: "the_geom",
MinOccurs: 0,
MaxOccurs: 1,
Expand Down Expand Up @@ -554,17 +554,17 @@ func TestCreateFeatureTypeNoDatastoreSuccess(t *testing.T) {
ProjectionPolicy: "NONE",
Enabled: true,
Metadata: []*FeatureTypeMetadata{
&FeatureTypeMetadata{
{
Key: "time",
Value: "<dimensionInfo><enabled>false</enabled><defaultValue/></dimensionInfo>",
},
&FeatureTypeMetadata{
{
Key: "cachingEnabled",
Value: "true",
},
},
Attributes: []*FeatureTypeAttribute{
&FeatureTypeAttribute{
{
Name: "the_geom",
MinOccurs: 0,
MaxOccurs: 1,
Expand Down Expand Up @@ -628,17 +628,17 @@ func TestCreateFeatureTypeNoDatastoreSuccess(t *testing.T) {
ProjectionPolicy: "NONE",
Enabled: true,
Metadata: []*FeatureTypeMetadata{
&FeatureTypeMetadata{
{
Key: "time",
Value: "<dimensionInfo><enabled>false</enabled><defaultValue/></dimensionInfo>",
},
&FeatureTypeMetadata{
{
Key: "cachingEnabled",
Value: "true",
},
},
Attributes: []*FeatureTypeAttribute{
&FeatureTypeAttribute{
{
Name: "the_geom",
MinOccurs: 0,
MaxOccurs: 1,
Expand Down Expand Up @@ -705,17 +705,17 @@ func TestCreateFeatureTypeInDatastoreSuccess(t *testing.T) {
ProjectionPolicy: "NONE",
Enabled: true,
Metadata: []*FeatureTypeMetadata{
&FeatureTypeMetadata{
{
Key: "time",
Value: "<dimensionInfo><enabled>false</enabled><defaultValue/></dimensionInfo>",
},
&FeatureTypeMetadata{
{
Key: "cachingEnabled",
Value: "true",
},
},
Attributes: []*FeatureTypeAttribute{
&FeatureTypeAttribute{
{
Name: "the_geom",
MinOccurs: 0,
MaxOccurs: 1,
Expand Down Expand Up @@ -779,17 +779,17 @@ func TestCreateFeatureTypeInDatastoreSuccess(t *testing.T) {
ProjectionPolicy: "NONE",
Enabled: true,
Metadata: []*FeatureTypeMetadata{
&FeatureTypeMetadata{
{
Key: "time",
Value: "<dimensionInfo><enabled>false</enabled><defaultValue/></dimensionInfo>",
},
&FeatureTypeMetadata{
{
Key: "cachingEnabled",
Value: "true",
},
},
Attributes: []*FeatureTypeAttribute{
&FeatureTypeAttribute{
{
Name: "the_geom",
MinOccurs: 0,
MaxOccurs: 1,
Expand Down Expand Up @@ -856,17 +856,17 @@ func TestUpdateFeatureTypeNoDatastoreSuccess(t *testing.T) {
ProjectionPolicy: "NONE",
Enabled: true,
Metadata: []*FeatureTypeMetadata{
&FeatureTypeMetadata{
{
Key: "time",
Value: "<dimensionInfo><enabled>false</enabled><defaultValue/></dimensionInfo>",
},
&FeatureTypeMetadata{
{
Key: "cachingEnabled",
Value: "true",
},
},
Attributes: []*FeatureTypeAttribute{
&FeatureTypeAttribute{
{
Name: "the_geom",
MinOccurs: 0,
MaxOccurs: 1,
Expand Down Expand Up @@ -930,17 +930,17 @@ func TestUpdateFeatureTypeNoDatastoreSuccess(t *testing.T) {
ProjectionPolicy: "NONE",
Enabled: true,
Metadata: []*FeatureTypeMetadata{
&FeatureTypeMetadata{
{
Key: "time",
Value: "<dimensionInfo><enabled>false</enabled><defaultValue/></dimensionInfo>",
},
&FeatureTypeMetadata{
{
Key: "cachingEnabled",
Value: "true",
},
},
Attributes: []*FeatureTypeAttribute{
&FeatureTypeAttribute{
{
Name: "the_geom",
MinOccurs: 0,
MaxOccurs: 1,
Expand Down