tileproxy

package module
v0.0.0-...-7655266 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 28, 2026 License: MIT Imports: 18 Imported by: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

# go-tileproxy

A high-performance tile proxy server written in Go, supporting multiple tile services and formats with caching capabilities.

## Features

- **Multiple Service Types**: Support for WMS, WMTS, Mapbox Vector Tiles, XYZ/OSM tiles, Cesium 3D Tiles, and ArcGIS REST services
- **Tile Formats**: PNG, JPEG, WebP, MVT, PBF, GeoJSON, Terrain, LERC
- **Caching System**: Local file-based cache with multiple layout options (TMS, Quadkey, ArcGIS, MapProxy)
- **Image Processing**: Tile merging, transformation, masking, and blank tile generation
- **Import/Export**: Support for MBTiles, GeoPackage, and COG formats
- **Reprojection**: Automatic tile reprojection between coordinate systems
- **Concurrent Processing**: Thread-safe operations with optimized performance

## Supported Services

- **MapboxService**: Mapbox Vector Tiles specification
- **WMSService**: Web Map Service (OGC standard) with GetMap and GetFeatureInfo support
- **WMTSService**: Web Map Tile Service (OGC standard)
- **TileService**: Standard XYZ/OSM tile services
- **CesiumService**: Cesium 3D Tiles specification
- **ArcGISService**: ArcGIS REST tile services

## Supported Tile Types

- `TILE_IMAGERY`: Raster image tiles (PNG, JPEG, WebP)
- `TILE_VECTOR`: Vector tiles (MVT, PBF, GeoJSON)
- `TILE_DEM`: Digital elevation model tiles (quantized mesh, terrain)

## Requirements

- Go 1.24 or higher

## Installation

```bash
go get github.com/flywave/go-tileproxy
```

## Configuration Validation & Hot Reload

Configuration can be validated and hot-reloaded without restarting the server:

- `setting.ValidateConfigJSON(data)` returns a structured, front-end friendly report (field-level errors/warnings per service) — see [docs/config-validation.md](docs/config-validation.md) for the full flywave-server integration guide.
- `proxy.ReloadFromFile(path, nil)` / `proxy.ReloadServices(services, nil)` apply a new configuration atomically; an invalid configuration never affects running services.
- `tileproxy serve --watch` watches the config file and hot-reloads on change; `tileproxy validate -c config.json` checks a config from the command line.

## HTTP Caching

Tile and capabilities responses are cache-friendly out of the box:

- Tile responses (TMS/WMTS/Cesium) carry `ETag` and `Last-Modified` and answer
  `If-None-Match` / `If-Modified-Since` with `304 Not Modified`.
- Setting `max_tile_age` additionally emits `Cache-Control: public, max-age=N, s-maxage=N`
  for CDN/browser freshness; without it clients revalidate instead.
- WMS/WMTS capabilities documents are rendered once per base URL, cached and
  revalidated via ETag, so repeated GetCapabilities requests are cheap.
- Concurrent cache-miss fetches for the same tile are collapsed by the tile
  locker (in-memory or file based), preventing thundering-herd upstream hits.

## Cache Policies

Per-cache policies decide when cached tiles are served and when the origin
sources are consulted: `cache_first` (default: serve whatever is cached until
it is cleaned), `ttl` (refresh after `ttl_hours`), `revalidate` (serve the
stale tile and refresh in the background) and `bypass` (origin only). See
[docs/cache-policy.md](docs/cache-policy.md) for the full behaviour matrix
and configuration examples.

## Usage

### Basic Example

```go
package main

import (
    "net/http"
    
    "github.com/flywave/go-tileproxy"
    "github.com/flywave/go-tileproxy/setting"
)

func main() {
    // Load configuration
    globals := &setting.GlobalsSetting{}
    services := []*setting.ProxyService{}
    cacheFactory := &setting.DefaultCacheFactory{}
    
    // Create tile proxy
    proxy := tileproxy.NewTileProxy(globals, services, cacheFactory)
    
    // Start HTTP server
    http.ListenAndServe(":8080", proxy)
}
```

### Running from Command Line

```bash
# Build the project
go build ./...

# Run tests
go test ./...

# Run the server
go run ./cmd/main.go
```

## Building

```bash
# Build all packages
go build ./...

# Build executable
go build -o tileproxy ./cmd
```

## Testing

```bash
# Run all tests
go test ./...

# Run tests with coverage
go test -cover ./...

# Run tests for a specific package
go test ./cache
go test ./service

# Run with verbose output
go test -v ./...
```

## Linting

```bash
# Format code
go fmt ./...

# Run vet
go vet ./...
```

## Project Structure

- `cache`: Cache management and local storage
- `client`: HTTP clients for different service types
- `service`: Service implementations for each protocol
- `layer`: Layer abstractions and source management
- `imagery`: Image processing and tile manipulation
- `terrain`: Terrain and DEM tile handling
- `vector`: Vector tile processing
- `sources`: Source implementations (WMS, ArcGIS, Mapbox, etc.)
- `request`: Request parsing and routing
- `imports`: Import handlers (MBTiles, GeoPackage, archives)
- `exports`: Export handlers (MBTiles, GeoPackage, COG)
- `setting`: Configuration and settings management
- `tile`: Tile definitions and options
- `utils`: Utility functions

## Configuration

The proxy uses a configuration-based approach where services, sources, caches, and grids are defined through settings. Each service can have:

- Multiple data sources (WMS, tile servers, etc.)
- Cache configurations with different layouts
- Grid definitions for projections and tile matrices
- Legend and feature info support where applicable

## License

MIT License - see [LICENSE](LICENSE) file for details.

## Contributing

1. Fork the repository
2. Create your feature branch
3. Commit your changes
4. Push to the branch
5. Create a Pull Request

Please ensure:
- Code follows the project's style guidelines
- All tests pass
- New features include tests
- Commits are clear and descriptive

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type ConfigWatcher

type ConfigWatcher struct {
	// contains filtered or unexported fields
}

ConfigWatcher watches a configuration file for changes and hot-reloads the proxy. It polls the file metadata and confirms a change by comparing content hashes, which keeps it reliable across editors that save via rename (a pattern inotify-style watchers easily miss) and needs no platform specific dependencies. Reload failures are logged and leave the running services untouched.

func NewConfigWatcher

func NewConfigWatcher(proxy *TileProxy, path string, fac setting.CacheFactory, interval, debounce time.Duration) *ConfigWatcher

func (*ConfigWatcher) Start

func (w *ConfigWatcher) Start()

Start begins watching in a background goroutine.

func (*ConfigWatcher) Stop

func (w *ConfigWatcher) Stop()

Stop terminates the watcher. It is safe to call multiple times.

type Service

type Service struct {
	setting.ProxyInstance
	Id      string
	Type    ServiceType
	Service service.Service

	Grids         map[string]geo.Grid
	Sources       map[string]layer.Layer
	InfoSources   map[string]layer.InfoLayer
	LegendSources map[string]layer.LegendLayer
	Caches        map[string]cache.Manager
	// contains filtered or unexported fields
}

func NewService

func NewService(dataset *setting.ProxyService, globals *setting.GlobalsSetting, fac setting.CacheFactory) *Service

func (*Service) Clean

func (s *Service) Clean()

func (*Service) GetCache

func (s *Service) GetCache(name string) cache.Manager

func (*Service) GetCacheSource

func (s *Service) GetCacheSource(name string, opt tile.TileOptions) layer.Layer

func (*Service) GetGrid

func (s *Service) GetGrid(name string) geo.Grid

func (*Service) GetId

func (s *Service) GetId() string

func (*Service) GetInfoSource

func (s *Service) GetInfoSource(name string) layer.InfoLayer

func (*Service) GetLegendSource

func (s *Service) GetLegendSource(name string) layer.LegendLayer

func (*Service) GetService

func (s *Service) GetService() service.Service

func (*Service) GetServiceType

func (s *Service) GetServiceType() ServiceType

func (*Service) GetSource

func (s *Service) GetSource(name string) layer.Layer

func (*Service) LoadError

func (s *Service) LoadError() error

func (*Service) Reload

func (s *Service) Reload(newConfig *setting.ProxyService, globals *setting.GlobalsSetting, fac setting.CacheFactory) error

func (*Service) ServeHTTP

func (s *Service) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Service) Status

func (s *Service) Status() ServiceStatus

type ServiceStatus

type ServiceStatus int32
const (
	ServiceStatusStopped  ServiceStatus = 0
	ServiceStatusStarting ServiceStatus = 1
	ServiceStatusRunning  ServiceStatus = 2
	ServiceStatusStopping ServiceStatus = 3
	ServiceStatusError    ServiceStatus = 4
)

func (ServiceStatus) String

func (s ServiceStatus) String() string

type ServiceType

type ServiceType uint32
const (
	MapboxService ServiceType = 0
	WMSService    ServiceType = 1
	WMTSService   ServiceType = 2
	TileService   ServiceType = 3
	CesiumService ServiceType = 4
)

func (ServiceType) String

func (t ServiceType) String() string

type TileProxy

type TileProxy struct {
	Services map[string]*Service
	// contains filtered or unexported fields
}

func NewTileProxy

func NewTileProxy(globals *setting.GlobalsSetting, proxys []*setting.ProxyService, fac setting.CacheFactory) *TileProxy

func (*TileProxy) GetService

func (t *TileProxy) GetService(id string) *Service

func (*TileProxy) GetServiceIDs

func (t *TileProxy) GetServiceIDs() []string

func (*TileProxy) Reload

func (t *TileProxy) Reload(proxy []*setting.ProxyService, fac setting.CacheFactory)

Reload replaces all services, logging instead of returning failures. It is kept for backwards compatibility; prefer ReloadServices.

func (*TileProxy) ReloadFromFile

func (t *TileProxy) ReloadFromFile(path string, fac setting.CacheFactory) error

ReloadFromFile loads a configuration file and applies it without stopping the server. When the file is missing, malformed or fails validation the currently running services are left untouched and the error is returned.

func (*TileProxy) ReloadServices

func (t *TileProxy) ReloadServices(services []*setting.ProxyService, fac setting.CacheFactory) error

ReloadServices atomically replaces the whole set of services. The new configuration is validated and built first; if anything fails the current services keep serving and the problems are returned. Retired services are drained and cleaned up in the background so in-flight requests finish safely.

func (*TileProxy) RemoveService

func (t *TileProxy) RemoveService(id string)

func (*TileProxy) ServeHTTP

func (s *TileProxy) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*TileProxy) SetRequestTimeout

func (t *TileProxy) SetRequestTimeout(timeout time.Duration)

func (*TileProxy) SetSlowLogThreshold

func (t *TileProxy) SetSlowLogThreshold(d time.Duration)

SetSlowLogThreshold sets the duration above which requests are logged. A negative value disables request logging entirely; zero restores the default of 200ms.

func (*TileProxy) Shutdown

func (t *TileProxy) Shutdown(ctx context.Context) error

func (*TileProxy) UpdateService

func (t *TileProxy) UpdateService(id string, d *setting.ProxyService, fac setting.CacheFactory) error

UpdateService builds and installs a single service, replacing an existing one with the same id. The running configuration is left untouched when the new service cannot be built.

Directories

Path Synopsis
amap command
arcgisonline command
baidu command
bingmap command
cesium command
google command
luokuang command
mapbox command
osm command
tianditu command
wms command
wmts command
ray

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL
⌂ 换网址