Git Product home page Git Product logo

geoserver's Introduction

Go Report Card GitHub license GitHub issues Coverage Status Build Status Documentation GitHub forks GitHub stars Twitter

Geoserver

geoserver Is a Go Package For Manipulating a GeoServer Instance via the GeoServer REST API.


How to install:

  • go get -v gopkg.in/hishamkaram/geoserver.v1
    • now you can import the package from gopkg.in/hishamkaram/geoserver.v1, example:
      import (
        ...
        "gopkg.in/hishamkaram/geoserver.v1"
        ...
      )
      

usage:

  • Create new Catalog (which contains all available operations):
    • gsCatalog := geoserver.GetCatalog("http://localhost:8080/geoserver13/", "admin", "geoserver")
  • Use catalog Methods to Perform a Geoserver REST Operation:
    • Create New workspace:
      created, err := gsCatalog.CreateWorkspace("golang")
      if err != nil {
        fmt.Printf("\nError:%s\n", err)
      }
      fmt.Println(strconv.FormatBool(created))
      
      output if created:
      INFO[31-03-2018 16:26:35] url:http://localhost:8080/geoserver13/rest/workspaces	response Status=201  
      true
      
      output if error:
      INFO[31-03-2018 16:26:37] url:http://localhost:8080/geoserver13/rest/workspaces	response Status=401  
      WARN[31-03-2018 16:26:37] <!doctype html><html lang="en"><head><title>HTTP Status 401 – Unauthorized</title><style type="text/css">h1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} h2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} h3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} body {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} b {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} p {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;} a {color:black;} a.name {color:black;} .line {height:1px;background-color:#525D76;border:none;}</style></head><body><h1>HTTP Status 401 – Unauthorized</h1><hr class="line" /><p><b>Type</b> Status Report</p><p><b>Message</b> Workspace &#39;golang&#39; already exists</p><p><b>Description</b> The request has not been applied because it lacks valid authentication credentials for the target resource.</p><hr class="line" /><h3>Apache Tomcat/9.0.6</h3></body></html> 
      
      Error:Unauthorized
      false
      
  • Get Layers through GetLayers take workspace as paramter if empty workspace will be ignored and geoserver will return all public layers
    layers, err := gsCatalog.GetLayers("")
    if err != nil {
      fmt.Printf("\nError:%s\n", err)
    }
    for _, lyr := range layers {
      fmt.Printf("\nName:%s  href:%s\n", lyr.Name, lyr.Href)
    }
    
    output:
    INFO[31-03-2018 19:04:44] url:http://localhost:8080/geoserver13/rest/layers	response Status=200  
    
    Name:tiger:giant_polygon  href:http://localhost:8080/geoserver13/rest/layers/tiger%3Agiant_polygon.json
    
    Name:tiger:poi  href:http://localhost:8080/geoserver13/rest/layers/tiger%3Apoi.json
    
    Name:tiger:poly_landmarks  href:http://localhost:8080/geoserver13/rest/layers/tiger%3Apoly_landmarks.json
    
    Name:tiger:tiger_roads  href:http://localhost:8080/geoserver13/rest/layers/tiger%3Atiger_roads.json
    
    Name:nurc:Arc_Sample  href:http://localhost:8080/geoserver13/rest/layers/nurc%3AArc_Sample.json
    
    Name:nurc:Img_Sample  href:http://localhost:8080/geoserver13/rest/layers/nurc%3AImg_Sample.json
    
    Name:nurc:Pk50095  href:http://localhost:8080/geoserver13/rest/layers/nurc%3APk50095.json
    
    Name:nurc:mosaic  href:http://localhost:8080/geoserver13/rest/layers/nurc%3Amosaic.json
    ......
    
  • Get Specific Layer from Geoserver:
    layer, err := gsCatalog.GetLayer("nurc", "Arc_Sample")
    if err != nil {
      fmt.Printf("\nError:%s\n", err)
    } else {
      fmt.Printf("%+v\n", layer)
    }
    
    output:
    INFO[31-03-2018 20:12:07] url:http://localhost:8080/geoserver13/rest/workspaces/nurc/layers/Arc_Sample	response Status=200  
    {Name:Arc_Sample Path:/ Type:RASTER DefaultStyle:{Class: Name:rain Href:http://localhost:8080/geoserver13/rest/styles/rain.json} Styles:{Class:linked-hash-set Style:[{Class: Name:raster Href:http://localhost:8080/geoserver13/rest/styles/raster.json}]} Resource:{Class:coverage Name:nurc:Arc_Sample Href:http://localhost:8080/geoserver13/rest/workspaces/nurc/coveragestores/arcGridSample/coverages/Arc_Sample.json} Queryable:false Opaque:false Attribution:{Title: Href: LogoURL: LogoType: LogoWidth:0 LogoHeight:0}}
    
  • You can find more examples by check testing files
  • You can find all supported operations on Godocs

TESTING

Go Version Geoserver Version Tested
1 1.13.x 2.13.x ✔️
2 1.13.x 2.14.x ✔️
3 1.14.x 2.13.x ✔️
4 1.14.x 2.14.x ✔️
5 1.15.x 2.13.x ✔️
6 1.15.x 2.14.x ✔️

geoserver's People

Contributors

deltabrot avatar hishamkaram avatar mdjong1 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

geoserver's Issues

Cannot Customize http client

If I try to connect to a geoserver with a self-signed cert geoserver fails. I suggest a way to customize the http client that the Geoserver struct is using. Currently it is unexported and I dont see a way to use a custom client if needed.

I have some problem,when i want to get layerGroups data by your api

i can't find get layerGroup's method, in your code. but i have fix it now by learning your code, thank you very much

`

    type Group struct {
        Type string `json:"@type,omitempty" xml:"type"`
        Name string `json:"name,omitempty" xml:"name"`
        Href string `json:"href,omitempty" xml:"href"`
    }
    type LayerGroup struct {
        Name      string `json:"name" xml:"name"`
        Mode      string `json:"mode" xml:"mode"`
        Title     string `json:"title" xml:"title"`
        Workspace struct {
	        Name string `json:"name" xml:"name"`
        } `json:"workspace" xml:"workspace"`
        Publishables struct {
	        Published []*Group `json:"published" xml:"published"`
        } `json:"publishables" xml:"publishables"`
        Styles struct {
	        Style []*Group `json:"style" xml:"style"`
        } `json:"styles" xml:"styles"`
        Bounds struct {
	        MinX float64 `json:"minx" xml:"minx"`
	        MinY float64 `json:"miny" xml:"miny"`
	        MaxX float64 `json:"maxx" xml:"maxx"`
	        MaxY float64 `json:"maxy" xml:"maxy"`
	        Crs  string  `json:"crs" xml:"crs"`
        } `json:"bounds" xml:"bounds"`
    }

    type LayerGroups struct {
        LayerGroup LayerGroup `json:"layerGroup" xml:"layerGroup"`
    }
    target := utils.Catalog.ParseURL("rest", "workspaces", workspace.Name, "layergroups", "xxxx")
request := geoserver.HTTPRequest{
	Method: "GET",
	Accept: "application/json",
	URL:    target,
	Query:  nil,
}
response, code := utils.Catalog.DoRequest(request)
if code != http.StatusOK {
	utils.Logger.Error("get layer groups error", zap.Int("error code", code))
	c.JSON(http.StatusInternalServerError, utils.BaseResponse(http.StatusInternalServerError, "internal server error", c.Request.RequestURI, nil))
	return
}
var groups defs.LayerGroups
utils.Catalog.DeSerializeJSON(response, &groups)
server := &defs.Server{
	BaseServiceUrl: utils.Catalog.ParseURL(workspace.Name, "wms?"),
	Layers:         fmt.Sprintf("%s:%s", groups.LayerGroup.Workspace.Name, groups.LayerGroup.Name),
	TilematrixSet:  groups.LayerGroup.Bounds.Crs,
}

`

i found you forgot a method about GetCoverageStore,right?

func (g *GeoServer) GetCoverageStore(workspaceName, gridName string) (coverageStore *CoverageStore, err error) {
	targetURL := g.ParseURL("rest", "workspaces", workspaceName, "coveragestores", gridName)
	httpRequest := HTTPRequest{
		Method: getMethod,
		Accept: jsonType,
		URL:    targetURL,
		Query:  nil,
	}
	response, responseCode := g.DoRequest(httpRequest)
	if responseCode != statusOk {
		g.logger.Error(string(response))
		coverageStore = nil
		err = g.GetError(responseCode, response)
		return
	}
	var coverageStoreResponse struct {
		CoverageStore *CoverageStore
	}
	g.DeSerializeJSON(response, &coverageStoreResponse)
	coverageStore = coverageStoreResponse.CoverageStore
	return
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.