mirror of
https://github.com/Luzifer/staticmap.git
synced 2024-12-20 12:51:18 +00:00
Compare commits
3 commits
aea881c15c
...
ad12e02404
Author | SHA1 | Date | |
---|---|---|---|
ad12e02404 | |||
5b51090fe9 | |||
7c1093f5bd |
10 changed files with 92 additions and 36 deletions
30
.github/workflows/test-and-build.yml
vendored
30
.github/workflows/test-and-build.yml
vendored
|
@ -16,7 +16,7 @@ jobs:
|
|||
shell: bash
|
||||
|
||||
container:
|
||||
image: luzifer/archlinux
|
||||
image: luzifer/gh-arch-env
|
||||
env:
|
||||
CGO_ENABLED: 0
|
||||
GOPATH: /go
|
||||
|
@ -24,32 +24,18 @@ jobs:
|
|||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- name: Enable custom AUR package repo
|
||||
run: echo -e "[luzifer]\nSigLevel = Never\nServer = https://archrepo.hub.luzifer.io/\$arch" >>/etc/pacman.conf
|
||||
|
||||
- name: Install required packages
|
||||
run: |
|
||||
pacman -Syy --noconfirm \
|
||||
awk \
|
||||
git \
|
||||
go \
|
||||
golangci-lint-bin \
|
||||
make \
|
||||
tar \
|
||||
zip
|
||||
|
||||
- uses: actions/checkout@v3
|
||||
- uses: actions/checkout@v4
|
||||
|
||||
- name: Marking workdir safe
|
||||
run: git config --global --add safe.directory /__w/staticmap/staticmap
|
||||
|
||||
- name: 'Lint and test code'
|
||||
run: |
|
||||
go test -cover -v ./...
|
||||
golangci-lint run ./...
|
||||
|
||||
- name: Build release
|
||||
run: make publish
|
||||
env:
|
||||
FORCE_SKIP_UPLOAD: 'true'
|
||||
MOD_MODE: readonly
|
||||
NO_TESTS: 'true'
|
||||
PACKAGES: '.'
|
||||
run: bash ci/build.sh
|
||||
|
||||
- name: Extract changelog
|
||||
run: 'awk "/^#/ && ++c==2{exit}; /^#/f" "History.md" | tail -n +2 >release_changelog.md'
|
||||
|
|
6
Makefile
6
Makefile
|
@ -1,9 +1,7 @@
|
|||
publish:
|
||||
curl -sSLo golang.sh https://raw.githubusercontent.com/Luzifer/github-publish/master/golang.sh
|
||||
bash golang.sh
|
||||
default:
|
||||
|
||||
update_example_post:
|
||||
curl -X POST --data-binary @example/postmap.json -o example/postmap.png localhost:5000/map.png
|
||||
|
||||
update_example_get:
|
||||
curl -o example/map.png 'localhost:5000/map.png?center=53.5438,9.9768&zoom=15&size=800x500&markers=color:blue|53.54129165,9.98420576699353&markers=color:yellow|53.54565525,9.9680555636958'
|
||||
curl -o example/map.png 'localhost:5000/map.png?center=53.5438,9.9768&zoom=15&size=800x500&markers=color:blue|53.54129165,9.98420576699353&markers=color:yellow|53.54565525,9.9680555636958&markers=size:tiny|color:red|53.54846472989871,9.978977621091543'
|
||||
|
|
|
@ -27,9 +27,10 @@ All map operations are made against the `/map.png` endpoint of the server and ar
|
|||
&size=800x500
|
||||
&markers=color:blue|53.54129165,9.98420576699353
|
||||
&markers=color:yellow|53.54565525,9.9680555636958
|
||||
&markers=size:tiny|color:red|53.54846472989871,9.978977621091543
|
||||
```
|
||||
|
||||
The map center is set to a coordinate within Hamburg, Germany with a zoom level of 15. Additionally there are two markers set: One `blue` marker to the Elbphilharmonie, one `yellow` marker to the Hard Rock Cafe Hamburg. The example above (of course without the line breaks) produced this image:
|
||||
The map center is set to a coordinate within Hamburg, Germany with a zoom level of 15. Additionally there are two markers set: One `blue` marker to the Elbphilharmonie, one `yellow` marker to the Hard Rock Cafe Hamburg and a `tiny` `red` marker on the St. Michaels church. The example above (of course without the line breaks) produced this image:
|
||||
|
||||
![](example/map.png)
|
||||
|
||||
|
|
63
ci/build.sh
Normal file
63
ci/build.sh
Normal file
|
@ -0,0 +1,63 @@
|
|||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
|
||||
osarch=(
|
||||
darwin/amd64
|
||||
darwin/arm64
|
||||
linux/amd64
|
||||
linux/arm
|
||||
linux/arm64
|
||||
windows/amd64
|
||||
)
|
||||
|
||||
function go_package() {
|
||||
cd "${4}"
|
||||
|
||||
local outname="${3}"
|
||||
[[ $1 == windows ]] && outname="${3}.exe"
|
||||
|
||||
log "=> Building ${3} for ${1}/${2}..."
|
||||
CGO_ENABLED=0 GOARCH=$2 GOOS=$1 go build \
|
||||
-ldflags "-s -w -X main.version=${version}" \
|
||||
-mod=readonly \
|
||||
-trimpath \
|
||||
-o "${outname}"
|
||||
|
||||
if [[ $1 == linux ]]; then
|
||||
log "=> Packging ${3} as ${3}_${1}_${2}.tgz..."
|
||||
tar -czf "${builddir}/${3}_${1}_${2}.tgz" "${outname}"
|
||||
else
|
||||
log "=> Packging ${3} as ${3}_${1}_${2}.zip..."
|
||||
zip "${builddir}/${3}_${1}_${2}.zip" "${outname}"
|
||||
fi
|
||||
|
||||
rm "${outname}"
|
||||
}
|
||||
|
||||
function go_package_all() {
|
||||
for oa in "${osarch[@]}"; do
|
||||
local os=$(cut -d / -f 1 <<<"${oa}")
|
||||
local arch=$(cut -d / -f 2 <<<"${oa}")
|
||||
(go_package "${os}" "${arch}" "${1}" "${2}")
|
||||
done
|
||||
}
|
||||
|
||||
function log() {
|
||||
echo "[$(date +%H:%M:%S)] $@" >&2
|
||||
}
|
||||
|
||||
root=$(pwd)
|
||||
builddir="${root}/.build"
|
||||
version="$(git describe --tags --always || echo dev)"
|
||||
|
||||
log "Building version ${version}..."
|
||||
|
||||
log "Resetting output directory..."
|
||||
rm -rf "${builddir}"
|
||||
mkdir -p "${builddir}"
|
||||
|
||||
log "Building Server..."
|
||||
go_package_all "staticmap" "."
|
||||
|
||||
log "Generating SHA256SUMS file..."
|
||||
(cd "${builddir}" && sha256sum * | tee SHA256SUMS)
|
BIN
example/map.png
BIN
example/map.png
Binary file not shown.
Before Width: | Height: | Size: 433 KiB After Width: | Height: | Size: 433 KiB |
|
@ -18,6 +18,14 @@
|
|||
"lat": 53.54565525,
|
||||
"lon": 9.9680555636958
|
||||
}
|
||||
},
|
||||
{
|
||||
"color": "red",
|
||||
"size": "tiny",
|
||||
"coord": {
|
||||
"lat": 53.54846472989871,
|
||||
"lon": 9.978977621091543
|
||||
}
|
||||
}
|
||||
],
|
||||
"overlays": [
|
||||
|
@ -25,4 +33,4 @@
|
|||
],
|
||||
"width": 800,
|
||||
"zoom": 15
|
||||
}
|
||||
}
|
Binary file not shown.
Before Width: | Height: | Size: 417 KiB After Width: | Height: | Size: 417 KiB |
8
main.go
8
main.go
|
@ -67,7 +67,7 @@ func main() {
|
|||
rateLimit.SetIPLookups([]string{"X-Forwarded-For", "RemoteAddr", "X-Real-IP"})
|
||||
|
||||
r := mux.NewRouter()
|
||||
r.HandleFunc("/status", func(res http.ResponseWriter, r *http.Request) { http.Error(res, "I'm fine", http.StatusOK) })
|
||||
r.HandleFunc("/status", func(res http.ResponseWriter, _ *http.Request) { http.Error(res, "I'm fine", http.StatusOK) })
|
||||
r.Handle("/map.png", tollbooth.LimitFuncHandler(rateLimit, handleMapRequest)).Methods("GET")
|
||||
r.Handle("/map.png", tollbooth.LimitFuncHandler(rateLimit, handlePostMapRequest)).Methods("POST")
|
||||
|
||||
|
@ -77,7 +77,7 @@ func main() {
|
|||
ReadHeaderTimeout: time.Second,
|
||||
}
|
||||
|
||||
logrus.WithField("version", version).Info("staticmap started")
|
||||
logrus.WithField("version", version).WithField("addr", cfg.Listen).Info("staticmap started")
|
||||
if err = server.ListenAndServe(); err != nil {
|
||||
logrus.WithError(err).Fatal("running HTTP server")
|
||||
}
|
||||
|
@ -173,7 +173,7 @@ func parseCoordinate(coord string) (s2.LatLng, error) {
|
|||
}
|
||||
|
||||
parts := strings.Split(coord, ",")
|
||||
if len(parts) != 2 { //nolint:gomnd
|
||||
if len(parts) != 2 { //nolint:mnd
|
||||
return s2.LatLng{}, errors.New("Coordinate not in format lat,lon")
|
||||
}
|
||||
|
||||
|
@ -200,7 +200,7 @@ func parseSize(size string) (x, y int, err error) {
|
|||
}
|
||||
|
||||
parts := strings.Split(size, "x")
|
||||
if len(parts) != 2 { //nolint:gomnd
|
||||
if len(parts) != 2 { //nolint:mnd
|
||||
return 0, 0, errors.New("Size not in format 600x300")
|
||||
}
|
||||
|
||||
|
|
6
map.go
6
map.go
|
@ -14,7 +14,7 @@ import (
|
|||
"github.com/pkg/errors"
|
||||
)
|
||||
|
||||
//nolint:gomnd // these are the "constant" definitions
|
||||
//nolint:mnd // these are the "constant" definitions
|
||||
var markerColors = map[string]color.Color{
|
||||
"black": color.RGBA{R: 145, G: 145, B: 145, A: 0xff},
|
||||
"brown": color.RGBA{R: 178, G: 154, B: 123, A: 0xff},
|
||||
|
@ -30,7 +30,7 @@ var markerColors = map[string]color.Color{
|
|||
|
||||
type markerSize float64
|
||||
|
||||
//nolint:gomnd // these are the "constant" definitions
|
||||
//nolint:mnd // these are the "constant" definitions
|
||||
var markerSizes = map[string]markerSize{
|
||||
"tiny": 10,
|
||||
"mid": 15,
|
||||
|
@ -97,7 +97,7 @@ func generateMap(opts generateMapConfig) (io.Reader, error) {
|
|||
|
||||
if opts.Markers != nil {
|
||||
for _, m := range opts.Markers {
|
||||
ctx.AddMarker(staticMap.NewMarker(m.pos, m.color, float64(m.size)))
|
||||
ctx.AddObject(staticMap.NewMarker(m.pos, m.color, float64(m.size)))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -105,7 +105,7 @@ func (p postMapOverlay) toOverlays() ([]*staticMap.TileProvider, error) {
|
|||
|
||||
result = append(result, &staticMap.TileProvider{
|
||||
Name: fmt.Sprintf("%x", sha256.Sum256([]byte(pat))),
|
||||
TileSize: 256, //nolint:gomnd
|
||||
TileSize: 256, //nolint:mnd
|
||||
URLPattern: pat,
|
||||
})
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue