diff --git a/cmd/seed.go b/cmd/seed.go index 8d9ce854..28bdfd36 100644 --- a/cmd/seed.go +++ b/cmd/seed.go @@ -7,8 +7,8 @@ import ( "os" "sync" + "github.com/Michad/tilegroxy/internal" "github.com/Michad/tilegroxy/internal/layers" - "github.com/Michad/tilegroxy/pkg" "github.com/spf13/cobra" ) @@ -63,13 +63,13 @@ Example: os.Exit(1) } - b := pkg.Bounds{MinLat: float64(minLat), MinLong: float64(minLon), MaxLat: float64(maxLat), MaxLong: float64(maxLon)} + b := internal.Bounds{MinLat: float64(minLat), MinLong: float64(minLon), MaxLat: float64(maxLat), MaxLong: float64(maxLon)} - tileRequests := make([]pkg.TileRequest, 0) + tileRequests := make([]internal.TileRequest, 0) for _, z := range zoom { - if z > pkg.MaxZoom { - fmt.Printf("Error: zoom must be less than %v\n", pkg.MaxZoom) + if z > internal.MaxZoom { + fmt.Printf("Error: zoom must be less than %v\n", internal.MaxZoom) os.Exit(1) } newTiles, err := b.FindTiles(layerName, uint(z), force) @@ -100,7 +100,7 @@ Example: chunkSize := int(math.Floor(float64(numReq) / float64(numThread))) - var reqSplit [][]pkg.TileRequest + var reqSplit [][]internal.TileRequest for i := 0; i < int(numThread); i++ { chunkStart := i * chunkSize @@ -118,7 +118,7 @@ Example: for t := int(0); t < len(reqSplit); t++ { wg.Add(1) - go func(t int, myReqs []pkg.TileRequest) { + go func(t int, myReqs []internal.TileRequest) { if verbose { fmt.Printf("Created thread %v with %v tiles\n", t, len(myReqs)) } diff --git a/cmd/test.go b/cmd/test.go index 27d5fe5a..6ce80bbc 100644 --- a/cmd/test.go +++ b/cmd/test.go @@ -9,10 +9,11 @@ import ( "sync" "text/tabwriter" + "sync/atomic" + + "github.com/Michad/tilegroxy/internal" "github.com/Michad/tilegroxy/internal/layers" - "github.com/Michad/tilegroxy/pkg" "github.com/spf13/cobra" - "sync/atomic" ) var testCmd = &cobra.Command{ @@ -57,10 +58,10 @@ Example: } //Generate the full list of requests to process - tileRequests := make([]pkg.TileRequest, 0) + tileRequests := make([]internal.TileRequest, 0) for _, layerName := range layerNames { - req := pkg.TileRequest{LayerName: layerName, Z: int(z), X: int(x), Y: int(y)} + req := internal.TileRequest{LayerName: layerName, Z: int(z), X: int(x), Y: int(y)} _, err := req.GetBounds() if err != nil { @@ -87,7 +88,7 @@ Example: //Split up all the requests for N threads numReqPerThread := int(math.Floor(float64(numReq) / float64(numThread))) - var reqSplit [][]pkg.TileRequest + var reqSplit [][]internal.TileRequest for i := 0; i < int(numThread); i++ { chunkStart := i * numReqPerThread @@ -110,7 +111,7 @@ Example: for t := int(0); t < len(reqSplit); t++ { wg.Add(1) - go func(t int, myReqs []pkg.TileRequest) { + go func(t int, myReqs []internal.TileRequest) { for _, req := range myReqs { layer := layerMap[req.LayerName] diff --git a/internal/caches/cache.go b/internal/caches/cache.go index 2c8a7015..28819f22 100644 --- a/internal/caches/cache.go +++ b/internal/caches/cache.go @@ -17,14 +17,14 @@ package caches import ( "fmt" + "github.com/Michad/tilegroxy/internal" "github.com/Michad/tilegroxy/internal/config" - "github.com/Michad/tilegroxy/pkg" "github.com/mitchellh/mapstructure" ) type Cache interface { - Lookup(t pkg.TileRequest) (*pkg.Image, error) - Save(t pkg.TileRequest, img *pkg.Image) error + Lookup(t internal.TileRequest) (*internal.Image, error) + Save(t internal.TileRequest, img *internal.Image) error } func ConstructCache(rawConfig map[string]interface{}, errorMessages *config.ErrorMessages) (Cache, error) { diff --git a/internal/caches/disk.go b/internal/caches/disk.go index 4abc7b48..4c95314b 100644 --- a/internal/caches/disk.go +++ b/internal/caches/disk.go @@ -22,8 +22,8 @@ import ( "path/filepath" "strconv" + "github.com/Michad/tilegroxy/internal" "github.com/Michad/tilegroxy/internal/config" - "github.com/Michad/tilegroxy/pkg" ) type DiskConfig struct { @@ -35,7 +35,7 @@ type Disk struct { config DiskConfig } -func requestToFilename(t pkg.TileRequest) string { +func requestToFilename(t internal.TileRequest) string { return t.LayerName + "_" + strconv.Itoa(t.Z) + "_" + strconv.Itoa(t.X) + "_" + strconv.Itoa(t.Y) } @@ -55,7 +55,7 @@ func ConstructDisk(config DiskConfig, ErrorMessages *config.ErrorMessages) (*Dis return &Disk{config}, nil } -func (c Disk) Lookup(t pkg.TileRequest) (*pkg.Image, error) { +func (c Disk) Lookup(t internal.TileRequest) (*internal.Image, error) { filename := requestToFilename(t) img, err := os.ReadFile(filepath.Join(c.config.Path, filename)) @@ -67,7 +67,7 @@ func (c Disk) Lookup(t pkg.TileRequest) (*pkg.Image, error) { return &img, err } -func (c Disk) Save(t pkg.TileRequest, img *pkg.Image) error { +func (c Disk) Save(t internal.TileRequest, img *internal.Image) error { filename := requestToFilename(t) return os.WriteFile(filepath.Join(c.config.Path, filename), *img, fs.FileMode(c.config.FileMode)) diff --git a/internal/caches/memcache.go b/internal/caches/memcache.go index 3eeb2a64..7b21e8db 100644 --- a/internal/caches/memcache.go +++ b/internal/caches/memcache.go @@ -14,17 +14,15 @@ package caches -import ( - "github.com/Michad/tilegroxy/pkg" -) +import "github.com/Michad/tilegroxy/internal" type Memcache struct { } -func (c Memcache) Lookup(t pkg.TileRequest) (*pkg.Image, error) { +func (c Memcache) Lookup(t internal.TileRequest) (*internal.Image, error) { return nil, nil } -func (c Memcache) Save(t pkg.TileRequest, img *pkg.Image) error { +func (c Memcache) Save(t internal.TileRequest, img *internal.Image) error { return nil } diff --git a/internal/caches/memory.go b/internal/caches/memory.go index a695066b..f1d275de 100644 --- a/internal/caches/memory.go +++ b/internal/caches/memory.go @@ -17,8 +17,8 @@ package caches import ( "time" + "github.com/Michad/tilegroxy/internal" "github.com/Michad/tilegroxy/internal/config" - "github.com/Michad/tilegroxy/pkg" "github.com/maypok86/otter" ) @@ -42,8 +42,8 @@ func ConstructMemory(config MemoryConfig, ErrorMessages *config.ErrorMessages) ( config.Ttl = 3600 } - cache, err := otter.MustBuilder[string, pkg.Image](int(config.MaxSize)). - Cost(func(key string, value pkg.Image) uint32 { + cache, err := otter.MustBuilder[string, internal.Image](int(config.MaxSize)). + Cost(func(key string, value internal.Image) uint32 { return uint32(len(value)) }). WithTTL(time.Duration(config.Ttl * uint32(time.Second))). @@ -55,10 +55,10 @@ func ConstructMemory(config MemoryConfig, ErrorMessages *config.ErrorMessages) ( return &Memory{config, cache}, nil } -func (c Memory) Lookup(t pkg.TileRequest) (*pkg.Image, error) { +func (c Memory) Lookup(t internal.TileRequest) (*internal.Image, error) { return nil, nil } -func (c Memory) Save(t pkg.TileRequest, img *pkg.Image) error { +func (c Memory) Save(t internal.TileRequest, img *internal.Image) error { return nil } diff --git a/internal/caches/multi.go b/internal/caches/multi.go index f9251ebe..17644d90 100644 --- a/internal/caches/multi.go +++ b/internal/caches/multi.go @@ -17,7 +17,7 @@ package caches import ( "errors" - "github.com/Michad/tilegroxy/pkg" + "github.com/Michad/tilegroxy/internal" ) type MultiConfig struct { @@ -28,7 +28,7 @@ type Multi struct { Tiers []Cache } -func (c Multi) Lookup(t pkg.TileRequest) (*pkg.Image, error) { +func (c Multi) Lookup(t internal.TileRequest) (*internal.Image, error) { var allErrors error for _, cache := range c.Tiers { @@ -45,7 +45,7 @@ func (c Multi) Lookup(t pkg.TileRequest) (*pkg.Image, error) { return nil, allErrors } -func (c Multi) Save(t pkg.TileRequest, img *pkg.Image) error { +func (c Multi) Save(t internal.TileRequest, img *internal.Image) error { var allErrors error for _, cache := range c.Tiers { diff --git a/internal/caches/noop.go b/internal/caches/noop.go index 3842f2c8..60733b53 100644 --- a/internal/caches/noop.go +++ b/internal/caches/noop.go @@ -14,17 +14,15 @@ package caches -import ( - "github.com/Michad/tilegroxy/pkg" -) +import "github.com/Michad/tilegroxy/internal" type Noop struct { } -func (c Noop) Lookup(t pkg.TileRequest) (*pkg.Image, error) { +func (c Noop) Lookup(t internal.TileRequest) (*internal.Image, error) { return nil, nil } -func (c Noop) Save(t pkg.TileRequest, img *pkg.Image) error { +func (c Noop) Save(t internal.TileRequest, img *internal.Image) error { return nil } diff --git a/internal/caches/redis.go b/internal/caches/redis.go index 3aa3f01a..0dc4181b 100644 --- a/internal/caches/redis.go +++ b/internal/caches/redis.go @@ -21,8 +21,8 @@ import ( "strconv" "time" + "github.com/Michad/tilegroxy/internal" "github.com/Michad/tilegroxy/internal/config" - "github.com/Michad/tilegroxy/pkg" "github.com/go-redis/cache/v9" "github.com/redis/go-redis/v9" @@ -49,7 +49,7 @@ type RedisConfig struct { Password string //Password to use to authenticate Mode string //Controls operating mode. One of AllModes. Defaults to standalone Ttl uint32 //Cache expiration in seconds. Default to 1 day - Servers []RedisServer //The list of servers to use. + Servers []RedisServer //The list of servers to use. } type Redis struct { @@ -80,7 +80,7 @@ func ConstructRedis(config *RedisConfig, errorMessages *config.ErrorMessages) (* } else { if config.Host != "" { return nil, fmt.Errorf(errorMessages.ParamsMutuallyExclusive, "config.redis.host", "config.redis.servers") - } + } } if config.Ttl == 0 { config.Ttl = 60 * 60 * 24 @@ -148,18 +148,18 @@ func ConstructRedis(config *RedisConfig, errorMessages *config.ErrorMessages) (* return &r, nil } -func (c Redis) Lookup(t pkg.TileRequest) (*pkg.Image, error) { +func (c Redis) Lookup(t internal.TileRequest) (*internal.Image, error) { ctx := context.TODO() key := c.KeyPrefix + t.String() - var obj pkg.Image + var obj internal.Image err := c.cache.Get(ctx, key, &obj) return &obj, err } -func (c Redis) Save(t pkg.TileRequest, img *pkg.Image) error { +func (c Redis) Save(t internal.TileRequest, img *internal.Image) error { ctx := context.TODO() key := c.KeyPrefix + t.String() diff --git a/internal/caches/s3.go b/internal/caches/s3.go index 16be7a49..42d86ca9 100644 --- a/internal/caches/s3.go +++ b/internal/caches/s3.go @@ -22,8 +22,8 @@ import ( "strconv" "strings" + "github.com/Michad/tilegroxy/internal" "github.com/Michad/tilegroxy/internal/config" - "github.com/Michad/tilegroxy/pkg" "github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws/awserr" "github.com/aws/aws-sdk-go/aws/credentials" @@ -112,11 +112,11 @@ func ConstructS3(config *S3Config, errorMessages *config.ErrorMessages) (*S3, er return &S3{config, downloader, uploader}, nil } -func calcKey(config *S3, t *pkg.TileRequest) string { +func calcKey(config *S3, t *internal.TileRequest) string { return config.Path + t.LayerName + "/" + strconv.Itoa(t.Z) + "/" + strconv.Itoa(t.X) + "/" + strconv.Itoa(t.Y) } -func (c S3) Lookup(t pkg.TileRequest) (*pkg.Image, error) { +func (c S3) Lookup(t internal.TileRequest) (*internal.Image, error) { writer := aws.NewWriteAtBuffer([]byte{}) _, err := c.downloader.Download( @@ -136,12 +136,12 @@ func (c S3) Lookup(t pkg.TileRequest) (*pkg.Image, error) { return nil, err } - img := pkg.Image(writer.Bytes()) + img := internal.Image(writer.Bytes()) return &img, nil } -func (c S3) Save(t pkg.TileRequest, img *pkg.Image) error { +func (c S3) Save(t internal.TileRequest, img *internal.Image) error { uploadConfig := &s3manager.UploadInput{ Bucket: &c.Bucket, diff --git a/internal/layers/layer.go b/internal/layers/layer.go index c5dee6a1..b5bda8db 100644 --- a/internal/layers/layer.go +++ b/internal/layers/layer.go @@ -21,10 +21,10 @@ import ( "sync" "time" + "github.com/Michad/tilegroxy/internal" "github.com/Michad/tilegroxy/internal/caches" "github.com/Michad/tilegroxy/internal/config" "github.com/Michad/tilegroxy/internal/providers" - "github.com/Michad/tilegroxy/pkg" ) type Layer struct { @@ -59,8 +59,8 @@ func (l *Layer) authWithProvider() error { return err } -func (l *Layer) RenderTile(tileRequest pkg.TileRequest) (*pkg.Image, error) { - var img *pkg.Image +func (l *Layer) RenderTile(tileRequest internal.TileRequest) (*internal.Image, error) { + var img *internal.Image var err error img, err = (*l.Cache).Lookup(tileRequest) @@ -89,8 +89,8 @@ func (l *Layer) RenderTile(tileRequest pkg.TileRequest) (*pkg.Image, error) { return img, nil } -func (l *Layer) RenderTileNoCache(tileRequest pkg.TileRequest) (*pkg.Image, error) { - var img *pkg.Image +func (l *Layer) RenderTileNoCache(tileRequest internal.TileRequest) (*internal.Image, error) { + var img *internal.Image var err error if l.authContext == nil || l.authContext.Expiration.Before(time.Now()) { diff --git a/internal/providers/provider.go b/internal/providers/provider.go index ad1a7470..c5555915 100644 --- a/internal/providers/provider.go +++ b/internal/providers/provider.go @@ -22,14 +22,14 @@ import ( "slices" "time" + "github.com/Michad/tilegroxy/internal" "github.com/Michad/tilegroxy/internal/config" - "github.com/Michad/tilegroxy/pkg" "github.com/mitchellh/mapstructure" ) type Provider interface { PreAuth(authContext *AuthContext) error - GenerateTile(authContext *AuthContext, clientConfig *config.ClientConfig, errorMessages *config.ErrorMessages, tileRequest pkg.TileRequest) (*pkg.Image, error) + GenerateTile(authContext *AuthContext, clientConfig *config.ClientConfig, errorMessages *config.ErrorMessages, tileRequest internal.TileRequest) (*internal.Image, error) } func ConstructProvider(rawConfig map[string]interface{}, errorMessages *config.ErrorMessages) (Provider, error) { @@ -92,7 +92,7 @@ func (e *RemoteServerError) Error() string { * Performs a GET operation against a given URL. Implementing providers should call this when possible. It has * standard reusable logic around various config options */ -func getTile(clientConfig *config.ClientConfig, url string, authHeaders map[string]string) (*pkg.Image, error) { +func getTile(clientConfig *config.ClientConfig, url string, authHeaders map[string]string) (*internal.Image, error) { slog.Debug(fmt.Sprintf("Calling url %v\n", url)) req, err := http.NewRequest(http.MethodGet, url, nil) diff --git a/internal/providers/proxy.go b/internal/providers/proxy.go index ad41c648..eed1a8c8 100644 --- a/internal/providers/proxy.go +++ b/internal/providers/proxy.go @@ -20,20 +20,20 @@ import ( "strconv" "strings" + "github.com/Michad/tilegroxy/internal" "github.com/Michad/tilegroxy/internal/config" - "github.com/Michad/tilegroxy/pkg" ) type Proxy struct { Url string - InvertY bool //Used for TMS + InvertY bool //Used for TMS } func (t Proxy) PreAuth(authContext *AuthContext) error { return nil } -func (t Proxy) GenerateTile(authContext *AuthContext, clientConfig *config.ClientConfig, errorMessages *config.ErrorMessages, tileRequest pkg.TileRequest) (*pkg.Image, error) { +func (t Proxy) GenerateTile(authContext *AuthContext, clientConfig *config.ClientConfig, errorMessages *config.ErrorMessages, tileRequest internal.TileRequest) (*internal.Image, error) { if t.Url == "" { return nil, fmt.Errorf(errorMessages.InvalidParam, "provider.proxy.url", "") } diff --git a/internal/providers/url_template.go b/internal/providers/url_template.go index 03a720fd..dcc2654d 100644 --- a/internal/providers/url_template.go +++ b/internal/providers/url_template.go @@ -19,8 +19,8 @@ import ( "strconv" "strings" + "github.com/Michad/tilegroxy/internal" "github.com/Michad/tilegroxy/internal/config" - "github.com/Michad/tilegroxy/pkg" ) type UrlTemplate struct { @@ -31,7 +31,7 @@ func (t UrlTemplate) PreAuth(authContext *AuthContext) error { return nil } -func (t UrlTemplate) GenerateTile(authContext *AuthContext, clientConfig *config.ClientConfig, errorMessages *config.ErrorMessages, tileRequest pkg.TileRequest) (*pkg.Image, error) { +func (t UrlTemplate) GenerateTile(authContext *AuthContext, clientConfig *config.ClientConfig, errorMessages *config.ErrorMessages, tileRequest internal.TileRequest) (*internal.Image, error) { if t.Template == "" { return nil, fmt.Errorf(errorMessages.InvalidParam, "provider.url template.url", "") } diff --git a/internal/server/tile_handler.go b/internal/server/tile_handler.go index bc6e2b31..961187bf 100644 --- a/internal/server/tile_handler.go +++ b/internal/server/tile_handler.go @@ -20,7 +20,7 @@ import ( "net/http" "strconv" - "github.com/Michad/tilegroxy/pkg" + "github.com/Michad/tilegroxy/internal" ) type tileHandler struct { @@ -63,12 +63,12 @@ func (h *tileHandler) ServeHTTP(w http.ResponseWriter, req *http.Request) { return } - tileReq := pkg.TileRequest{LayerName: layerName, Z: z, X: x, Y: y} + tileReq := internal.TileRequest{LayerName: layerName, Z: z, X: x, Y: y} _, err = tileReq.GetBounds() if err != nil { - var re pkg.RangeError + var re internal.RangeError if errors.As(err, &re) { writeError(w, &h.config.Error, http.StatusBadRequest, h.config.Error.Messages.RangeError, re.ParamName, re.MinValue, re.MaxValue) } else { diff --git a/pkg/tile_request.go b/internal/tile_request.go similarity index 99% rename from pkg/tile_request.go rename to internal/tile_request.go index 691462ac..be3475a9 100644 --- a/pkg/tile_request.go +++ b/internal/tile_request.go @@ -1,4 +1,4 @@ -package pkg +package internal import ( "fmt" diff --git a/pkg/tile_request_test.go b/internal/tile_request_test.go similarity index 99% rename from pkg/tile_request_test.go rename to internal/tile_request_test.go index d4501775..5942d754 100644 --- a/pkg/tile_request_test.go +++ b/internal/tile_request_test.go @@ -1,4 +1,4 @@ -package pkg +package internal import ( "errors" diff --git a/pkg/types.go b/internal/types.go similarity index 55% rename from pkg/types.go rename to internal/types.go index 46772d36..860b9847 100644 --- a/pkg/types.go +++ b/internal/types.go @@ -1,3 +1,3 @@ -package pkg +package internal type Image = []byte