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

Applied gofmt and most of go lint's suggestions #192

Merged
merged 2 commits into from
Oct 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions cql/cql.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func syntaxErrorMsg(input string, col int) string {
return msg
}

//======================================
// ======================================
type CqlErrorListener struct {
*antlr.DefaultErrorListener
errorCount int
Expand Down Expand Up @@ -162,7 +162,7 @@ func getNodeText(node antlr.TerminalNode) string {
return node.GetText()
}

//========================================
// ========================================
type CqlContext struct {
*antlr.BaseParserRuleContext
// SQL fragment for the context subtree
Expand Down
3 changes: 2 additions & 1 deletion cql/cqlparser_base_listener.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ func (s *BaseCQLParserListener) EnterBinaryComparisonPredicate(ctx *BinaryCompar
}

// ExitBinaryComparisonPredicate is called when production binaryComparisonPredicate is exited.
func (s *BaseCQLParserListener) ExitBinaryComparisonPredicate(ctx *BinaryComparisonPredicateContext) {}
func (s *BaseCQLParserListener) ExitBinaryComparisonPredicate(ctx *BinaryComparisonPredicateContext) {
}

// EnterLikePredicate is called when production likePredicate is entered.
func (s *BaseCQLParserListener) EnterLikePredicate(ctx *LikePredicateContext) {}
Expand Down
4 changes: 2 additions & 2 deletions layer.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"errors"
"fmt"

"net/http"
Expand Down Expand Up @@ -43,6 +42,7 @@ type Layer interface {
WriteLayerJSON(w http.ResponseWriter, req *http.Request) error
}

// A TileRequest specifies what to fetch from the database for a single tile
type TileRequest struct {
LayerID string
Tile Tile
Expand All @@ -55,7 +55,7 @@ func getLayer(lyrID string) (Layer, error) {
if ok {
return lyr, nil
}
return lyr, errors.New(fmt.Sprintf("Unable to get layer '%s'", lyrID))
return lyr, fmt.Errorf("Unable to get layer '%s'", lyrID)
}

func loadLayers() error {
Expand Down
9 changes: 9 additions & 0 deletions layer_proc.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,26 +54,34 @@ type FunctionDetailJSON struct {
* Layer Interface
*/

// GetType disambiguates between function and table layers
func (lyr LayerFunction) GetType() LayerType {
return LayerTypeFunction
}

// GetID returns the complete ID (schema.name) by which to reference a given layer
func (lyr LayerFunction) GetID() string {
return lyr.ID
}

// GetDescription returns the text description for a layer
// or an empty string if no description is set
func (lyr LayerFunction) GetDescription() string {
return lyr.Description
}

// GetName returns just the name of a given layer
func (lyr LayerFunction) GetName() string {
return lyr.Function
}

// GetSchema returns just the schema for a given layer
func (lyr LayerFunction) GetSchema() string {
return lyr.Schema
}

// GetTileRequest takes tile and request parameters as input and returns a TileRequest
// specifying the SQL and any additional arguments to fetch appropriate data
func (lyr LayerFunction) GetTileRequest(tile Tile, r *http.Request) TileRequest {

procArgs := lyr.getFunctionArgs(r.URL.Query())
Expand All @@ -88,6 +96,7 @@ func (lyr LayerFunction) GetTileRequest(tile Tile, r *http.Request) TileRequest
return tr
}

// WriteLayerJSON outputs parameters and optional arguments for the function layer
func (lyr LayerFunction) WriteLayerJSON(w http.ResponseWriter, req *http.Request) error {
jsonTableDetail, err := lyr.getFunctionDetailJSON(req)
if err != nil {
Expand Down
16 changes: 16 additions & 0 deletions layer_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"github.com/spf13/viper"
)

// LayerTable provides metadata about the table layer
type LayerTable struct {
ID string
Schema string
Expand All @@ -33,13 +34,16 @@ type LayerTable struct {
Srid int
}

// TableProperty provides metadata about a single property field,
// features in a table layer may have multiple such fields
type TableProperty struct {
Name string `json:"name"`
Type string `json:"type"`
Description string `json:"description"`
order int
}

// TableDetailJSON gives the output structure for the table layer.
type TableDetailJSON struct {
ID string `json:"id"`
Schema string `json:"schema"`
Expand All @@ -58,26 +62,33 @@ type TableDetailJSON struct {
* Layer Interface
*/

// GetType disambiguates between function and table layers
func (lyr LayerTable) GetType() LayerType {
return LayerTypeTable
}

// GetID returns the complete ID (schema.name) by which to reference a given layer
func (lyr LayerTable) GetID() string {
return lyr.ID
}

// GetDescription returns the text description for a layer
// or an empty string if no description is set
func (lyr LayerTable) GetDescription() string {
return lyr.Description
}

// GetName returns just the name of a given layer
func (lyr LayerTable) GetName() string {
return lyr.Table
}

// GetSchema returns just the schema for a given layer
func (lyr LayerTable) GetSchema() string {
return lyr.Schema
}

// WriteLayerJSON outputs parameters and optional arguments for the table layer
func (lyr LayerTable) WriteLayerJSON(w http.ResponseWriter, req *http.Request) error {
jsonTableDetail, err := lyr.getTableDetailJSON(req)
if err != nil {
Expand All @@ -89,6 +100,8 @@ func (lyr LayerTable) WriteLayerJSON(w http.ResponseWriter, req *http.Request) e
return nil
}

// GetTileRequest takes tile and request parameters as input and returns a TileRequest
// specifying the SQL to fetch appropriate data
func (lyr LayerTable) GetTileRequest(tile Tile, r *http.Request) TileRequest {
rp := lyr.getQueryParameters(r.URL.Query())
sql, _ := lyr.requestSQL(&tile, &rp)
Expand Down Expand Up @@ -262,6 +275,8 @@ func (lyr *LayerTable) getTableDetailJSON(req *http.Request) (TableDetailJSON, e
return td, nil
}

// GetBoundsExact returns the data coverage extent for a table layer
// in EPSG:4326, clipped to (+/-180, +/-90)
func (lyr *LayerTable) GetBoundsExact() (Bounds, error) {
bounds := Bounds{}
extentSQL := fmt.Sprintf(`
Expand Down Expand Up @@ -308,6 +323,7 @@ func (lyr *LayerTable) GetBoundsExact() (Bounds, error) {
return bounds, nil
}

// GetBounds returns the estimated extent for a table layer, transformed to EPSG:4326
func (lyr *LayerTable) GetBounds() (Bounds, error) {
bounds := Bounds{}
extentSQL := fmt.Sprintf(`
Expand Down
10 changes: 5 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,21 +40,21 @@ import (
const programName string = "pg_tileserv"

// programVersion is the version string we use
//const programVersion string = "0.1"
// const programVersion string = "0.1"
var programVersion string

// globalDb is a global database connection pointer
var globalDb *pgxpool.Pool = nil
var globalDb *pgxpool.Pool

// globalVersions holds the parsed output of postgis_full_version()
var globalVersions map[string]string = nil
var globalVersions map[string]string

// globalPostGISVersion is numeric, sortable postgis version (3.2.1 => 3002001)
var globalPostGISVersion int = 0
var globalPostGISVersion int

// serverBounds are the coordinate reference system and extent from
// which tiles are constructed
var globalServerBounds *Bounds = nil
var globalServerBounds *Bounds
Comment on lines -47 to +57
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was surprised by this set of go lint suggestions, but the rationale it offers is that in each case the assignment is of what would be the default value anyway.


// timeToLive is the Cache-Control timeout value that will be advertised
// in the response headers
Expand Down
3 changes: 1 addition & 2 deletions tile.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"errors"
"fmt"
"math"
"strconv"
Expand Down Expand Up @@ -34,7 +33,7 @@ func makeTile(vars map[string]string) (Tile, error) {
if !tile.IsValid() {
invalidTileError := tileAppError{
HTTPCode: 400,
SrcErr: errors.New(fmt.Sprintf("invalid tile address %s", tile.String())),
SrcErr: fmt.Errorf("invalid tile address %s", tile.String()),
}
return tile, invalidTileError
}
Expand Down
1 change: 1 addition & 0 deletions util.go
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,7 @@ type metricsResponseWriter struct {
StatusCode int
}

// NewMetricsResponseWriter instantiates and returns a metricsResponseWriter
func NewMetricsResponseWriter(w http.ResponseWriter) *metricsResponseWriter {
return &metricsResponseWriter{w, http.StatusOK}
}
Expand Down
Loading