Compare commits
22 Commits
Author | SHA1 | Date | |
---|---|---|---|
e31652d481 | |||
42a82d3e97 | |||
f345fe3b2c | |||
8b8b818651 | |||
06740b6b86 | |||
6d5c00653b | |||
ead6298a55 | |||
454419abec | |||
b53357aad7 | |||
fee92259b1 | |||
c964c73824 | |||
c2882857a4 | |||
f207f57536 | |||
30fbf1b611 | |||
70900ea2c7 | |||
322e908147 | |||
308f853b81 | |||
d5de8568dd | |||
8b80a73452 | |||
20366ed3e4 | |||
1c52aae429 | |||
c0bd927903 |
30
.drone.yml
30
.drone.yml
@ -3,28 +3,20 @@ name: default
|
||||
|
||||
steps:
|
||||
- name: build
|
||||
image: golang:latest
|
||||
image: tystuyfzand/goc
|
||||
group: build
|
||||
volumes:
|
||||
- name: build
|
||||
path: /build
|
||||
commands:
|
||||
- mkdir -p /build/i386 /build/amd64 /build/armv7 /build/arm64
|
||||
- GOOS=linux GOARCH=386 go build -o /build/i386/owapi_i386
|
||||
- go build -o /build/amd64/owapi_amd64
|
||||
- GOOS=linux GOARCH=arm GOARM=7 go build -o /build/armv7/owapi_armv7
|
||||
- GOOS=linux GOARCH=arm64 go build -o /build/arm64/owapi_arm64
|
||||
- GOOS=linux,windows GOARCH=386,arm,arm64,amd64 goc -o /build/owapi
|
||||
- name: package
|
||||
image: tystuyfzand/fpm
|
||||
commands:
|
||||
- export VERSION=`grep "Version" main.go | head -n 1 | awk '{print $3}' | sed -e 's/^"//' -e 's/"$//' | tr -d '\n'`
|
||||
- echo "v$VERSION" > /build/version.txt
|
||||
- chmod +x packaging/build-package.sh packaging/package-upload.sh
|
||||
- ARCH=i386 packaging/build-package.sh
|
||||
- ARCH=amd64 packaging/build-package.sh
|
||||
- ARCH=armv7 packaging/build-package.sh
|
||||
- ARCH=arm64 packaging/build-package.sh
|
||||
- packaging/package-upload.sh
|
||||
- chmod +x packaging/build-package.sh
|
||||
- ARCH=386,amd64,armv7,arm64 packaging/build-package.sh
|
||||
volumes:
|
||||
- name: build
|
||||
path: /build
|
||||
@ -40,11 +32,21 @@ steps:
|
||||
gitea_server: https://git.meow.tf
|
||||
tag_file: /build/version.txt
|
||||
title_file: /build/version.txt
|
||||
files: [ '/build/*/owapi_*' ]
|
||||
files: [ '/build/owapi_*' ]
|
||||
environment:
|
||||
PLUGIN_API_KEY:
|
||||
from_secret: gitea_token
|
||||
|
||||
- name: docker
|
||||
image: plugins/docker
|
||||
settings:
|
||||
username:
|
||||
from_secret: docker_username
|
||||
password:
|
||||
from_secret: docker_password
|
||||
repo: registry.meow.tf/ow-api/ow-api
|
||||
registry: registry.meow.tf
|
||||
tags:
|
||||
- latest
|
||||
volumes:
|
||||
- name: build
|
||||
temp: {}
|
11
Dockerfile
Normal file
11
Dockerfile
Normal file
@ -0,0 +1,11 @@
|
||||
FROM golang:alpine AS builder
|
||||
|
||||
ADD . /build
|
||||
|
||||
RUN cd /build && go build -o ow-api
|
||||
|
||||
FROM golang:alpine
|
||||
|
||||
COPY --from=builder /build/ow-api /usr/bin/ow-api
|
||||
|
||||
CMD [ "/usr/bin/ow-api" ]
|
5
LICENSE
Normal file
5
LICENSE
Normal file
@ -0,0 +1,5 @@
|
||||
Copyright 2020 Tyler Stuyfzand <admin@meow.tf>
|
||||
|
||||
Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
10
endpoints.go
10
endpoints.go
@ -12,7 +12,7 @@ import (
|
||||
)
|
||||
|
||||
func stats(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
data, err := statsResponse(w, ps, nil)
|
||||
data, err := statsResponse(w, r, ps, nil)
|
||||
|
||||
if err != nil {
|
||||
writeError(w, err)
|
||||
@ -25,7 +25,7 @@ func stats(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
}
|
||||
|
||||
func profile(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
cacheKey := generateCacheKey(ps) + "-profile"
|
||||
cacheKey := generateCacheKey(r, ps) + "-profile"
|
||||
|
||||
res, err := cacheProvider.Get(cacheKey)
|
||||
|
||||
@ -36,7 +36,7 @@ func profile(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
}
|
||||
|
||||
// Cache result for profile specifically
|
||||
data, err := statsResponse(w, ps, profilePatch)
|
||||
data, err := statsResponse(w, r, ps, profilePatch)
|
||||
|
||||
if err != nil {
|
||||
writeError(w, err)
|
||||
@ -63,7 +63,7 @@ func heroes(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
|
||||
sort.Strings(names)
|
||||
|
||||
cacheKey := generateCacheKey(ps) + "-heroes-" + hex.EncodeToString(md5.New().Sum([]byte(strings.Join(names, ","))))
|
||||
cacheKey := generateCacheKey(r, ps) + "-heroes-" + hex.EncodeToString(md5.New().Sum([]byte(strings.Join(names, ","))))
|
||||
|
||||
res, err := cacheProvider.Get(cacheKey)
|
||||
|
||||
@ -108,7 +108,7 @@ func heroes(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
}
|
||||
|
||||
// Create a patch to remove all but specified heroes
|
||||
data, err := statsResponse(w, ps, patch)
|
||||
data, err := statsResponse(w, r, ps, patch)
|
||||
|
||||
if err != nil {
|
||||
writeError(w, err)
|
||||
|
15
go.mod
15
go.mod
@ -3,20 +3,15 @@ module git.meow.tf/ow-api/ow-api
|
||||
go 1.12
|
||||
|
||||
require (
|
||||
github.com/PuerkitoBio/goquery v1.5.1-0.20190109230704-3dcf72e6c17f
|
||||
github.com/andybalholm/cascadia v1.1.0 // indirect
|
||||
github.com/PuerkitoBio/goquery v1.6.1
|
||||
github.com/bluele/gcache v0.0.0-20190518031135-bc40bd653833
|
||||
github.com/bradfitz/gomemcache v0.0.0-20190913173617-a41fca850d0b
|
||||
github.com/go-redis/redis v6.15.6+incompatible
|
||||
github.com/julienschmidt/httprouter v1.3.0
|
||||
github.com/kr/pretty v0.1.0 // indirect
|
||||
github.com/miekg/dns v1.1.26
|
||||
github.com/onsi/ginkgo v1.8.0 // indirect
|
||||
github.com/onsi/gomega v1.5.0 // indirect
|
||||
github.com/rs/cors v1.7.0
|
||||
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 // indirect
|
||||
golang.org/x/sync v0.0.0-20190911185100-cd5d95a43a6e // indirect
|
||||
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
|
||||
gopkg.in/yaml.v2 v2.2.2 // indirect
|
||||
s32x.com/ovrstat v0.0.0-20191125185405-f48c0d280dc1
|
||||
github.com/stoewer/go-strcase v1.2.0
|
||||
github.com/stretchr/objx v0.2.0 // indirect
|
||||
golang.org/x/net v0.0.0-20200822124328-c89045814202
|
||||
s32x.com/ovrstat v0.0.0-20210411215317-b668284adcc8
|
||||
)
|
||||
|
69
go.sum
69
go.sum
@ -1,5 +1,9 @@
|
||||
github.com/PuerkitoBio/goquery v1.5.1-0.20190109230704-3dcf72e6c17f h1:cWOyRTtBcTBjB0c+GyaQaXgP3g1HVM1KbvZL/Q5QNAM=
|
||||
github.com/PuerkitoBio/goquery v1.5.1-0.20190109230704-3dcf72e6c17f/go.mod h1:qD2PgZ9lccMbQlc7eEOjaeRlFQON7xY8kdmcsrnKqMg=
|
||||
github.com/PuerkitoBio/goquery v1.5.1 h1:PSPBGne8NIUWw+/7vFBV+kG2J/5MOjbzc7154OaKCSE=
|
||||
github.com/PuerkitoBio/goquery v1.5.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
|
||||
github.com/PuerkitoBio/goquery v1.6.1 h1:FgjbQZKl5HTmcn4sKBgvx8vv63nhyhIpv7lJpFGCWpk=
|
||||
github.com/PuerkitoBio/goquery v1.6.1/go.mod h1:GsLWisAFVj4WgDibEWF4pvYnkVQBpKBKeU+7zCJoLcc=
|
||||
github.com/andybalholm/cascadia v1.0.0 h1:hOCXnnZ5A+3eVDX8pvgl4kofXv2ELss0bKcqRySc45o=
|
||||
github.com/andybalholm/cascadia v1.0.0/go.mod h1:GsXiBklL0woXo1j/WYWtSYYC4ouU9PqHO0sqidkEA4Y=
|
||||
github.com/andybalholm/cascadia v1.1.0 h1:BuuO6sSfQNFRu1LppgbD25Hr2vLYW25JvxHs5zzsLTo=
|
||||
@ -29,11 +33,30 @@ github.com/kr/pretty v0.1.0/go.mod h1:dAy3ld7l9f0ibDNOQOHHMYYIIbhfbHSm3C4ZsoJORN
|
||||
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
|
||||
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
|
||||
github.com/labstack/echo/v4 v4.1.7-0.20190725203903-8cabd1e123d6 h1:ImU76UGnZN9+25dYuM+4uMhP0TFf/nT61rLy1RPPKUM=
|
||||
github.com/labstack/echo/v4 v4.1.7-0.20190725203903-8cabd1e123d6/go.mod h1:kU/7PwzgNxZH4das4XNsSpBSOD09XIF5YEPzjpkGnGE=
|
||||
github.com/labstack/echo/v4 v4.1.14 h1:h8XP66UfB3tUm+L3QPw7tmwAu3pJaA/nyfHPCcz46ic=
|
||||
github.com/labstack/echo/v4 v4.1.14/go.mod h1:Q5KZ1vD3V5FEzjM79hjwVrC3ABr7F5IdM23bXQMRDGg=
|
||||
github.com/labstack/echo/v4 v4.1.17 h1:PQIBaRplyRy3OjwILGkPg89JRtH2x5bssi59G2EL3fo=
|
||||
github.com/labstack/echo/v4 v4.1.17/go.mod h1:Tn2yRQL/UclUalpb5rPdXDevbkJ+lp/2svdyFBg6CHQ=
|
||||
github.com/labstack/echo/v4 v4.2.0 h1:jkCSsjXmBmapVXF6U4BrSz/cgofWM0CU3Q74wQvXkIc=
|
||||
github.com/labstack/echo/v4 v4.2.0/go.mod h1:AA49e0DZ8kk5jTOOCKNuPR6oTnBS0dYiM4FW1e6jwpg=
|
||||
github.com/labstack/gommon v0.2.9 h1:heVeuAYtevIQVYkGj6A41dtfT91LrvFG220lavpWhrU=
|
||||
github.com/labstack/gommon v0.2.9/go.mod h1:E8ZTmW9vw5az5/ZyHWCp0Lw4OH2ecsaBP1C/NKavGG4=
|
||||
github.com/labstack/gommon v0.3.0 h1:JEeO0bvc78PKdyHxloTKiF8BD5iGrH8T6MSeGvSgob0=
|
||||
github.com/labstack/gommon v0.3.0/go.mod h1:MULnywXg0yavhxWKc+lOruYdAhDwPK9wf0OL7NoOu+k=
|
||||
github.com/mattn/go-colorable v0.1.2 h1:/bC9yWikZXAL9uJdulbSfyVNIR3n3trXl+v8+1sx8mU=
|
||||
github.com/mattn/go-colorable v0.1.2/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
||||
github.com/mattn/go-colorable v0.1.4 h1:snbPLB8fVfU9iwbbo30TPtbLRzwWu6aJS6Xh4eaaviA=
|
||||
github.com/mattn/go-colorable v0.1.4/go.mod h1:U0ppj6V5qS13XJ6of8GYAs25YV2eR4EVcfRqFIhoBtE=
|
||||
github.com/mattn/go-colorable v0.1.7 h1:bQGKb3vps/j0E9GfJQ03JyhRuxsvdAanXlT9BTw3mdw=
|
||||
github.com/mattn/go-colorable v0.1.7/go.mod h1:u6P/XSegPjTcexA+o6vUJrdnUu04hMope9wVRipJSqc=
|
||||
github.com/mattn/go-isatty v0.0.8 h1:HLtExJ+uU2HOZ+wI0Tt5DtUDrx8yhUqDcp7fYERX4CE=
|
||||
github.com/mattn/go-isatty v0.0.8/go.mod h1:Iq45c/XA43vh69/j3iqttzPXn0bhXyGjM0Hdxcsrc5s=
|
||||
github.com/mattn/go-isatty v0.0.9/go.mod h1:YNRxwqDuOph6SZLI9vUUz6OYw3QyUt7WiY2yME+cCiQ=
|
||||
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
|
||||
github.com/mattn/go-isatty v0.0.12 h1:wuysRhFDzyxgEmMf5xjvJ2M9dZoWAXNNr5LSBS7uHXY=
|
||||
github.com/mattn/go-isatty v0.0.12/go.mod h1:cbi8OIDigv2wuxKPP5vlRcQ1OAZbq2CE4Kysco4FUpU=
|
||||
github.com/miekg/dns v1.1.26 h1:gPxPSwALAeHJSjarOs00QjVdV9QoBvc1D2ujQUr5BzU=
|
||||
github.com/miekg/dns v1.1.26/go.mod h1:bPDLeHnStXmXAq1m/Ch/hvfNHr14JKNPMBo3VZKjuso=
|
||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
@ -43,20 +66,40 @@ github.com/onsi/gomega v1.5.0 h1:izbySO9zDPmjJ8rDjLvkA2zJHIo+HkYXHnf7eN7SSyo=
|
||||
github.com/onsi/gomega v1.5.0/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||
github.com/pkg/errors v0.8.1 h1:iURUrRGxPUNPdy5/HRSm+Yj6okJ6UtLINN0Q9M4+h3I=
|
||||
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
|
||||
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rs/cors v1.7.0 h1:+88SsELBHx5r+hZ8TCkggzSstaWNbDvThkVK8H6f9ik=
|
||||
github.com/rs/cors v1.7.0/go.mod h1:gFx+x8UowdsKA9AchylcLynDq+nNFfI8FkUZdN/jGCU=
|
||||
github.com/seilem/ovrstat v0.0.0-20200123200456-7b7e24d39506 h1:xAdnQYUFimq8Uiz4Io7QlnNGV+4BtagWGC+DDxVG3Fo=
|
||||
github.com/seilem/ovrstat v0.0.0-20200123200456-7b7e24d39506/go.mod h1:UzsLSEoY8B4FByz4e+5GGKebJio+H+axo3RxLr7d7Mw=
|
||||
github.com/stoewer/go-strcase v1.2.0 h1:Z2iHWqGXH00XYgqDmNgQbIBxf3wrNq0F3feEy0ainaU=
|
||||
github.com/stoewer/go-strcase v1.2.0/go.mod h1:IBiWB2sKIp3wVVQ3Y035++gc+knqhUQag1KpM8ahLw8=
|
||||
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/objx v0.2.0/go.mod h1:qt09Ya8vawLte6SNmTgCsAVtYtaKzEcn8ATUoHMkEqE=
|
||||
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
|
||||
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
|
||||
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
|
||||
github.com/tystuyfzand/ovrstat v0.0.0-20201003203341-5f1ad8502a8f h1:vjYPeN0jt5TJ1vP4teWyTLGbkufQoPi0bhYE9wzg/4w=
|
||||
github.com/tystuyfzand/ovrstat v0.0.0-20201003203341-5f1ad8502a8f/go.mod h1:UzsLSEoY8B4FByz4e+5GGKebJio+H+axo3RxLr7d7Mw=
|
||||
github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw=
|
||||
github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc=
|
||||
github.com/valyala/fasttemplate v1.0.1 h1:tY9CJiPnMXf1ERmG2EyK7gNUd+c6RKGD0IfU8WdUSz8=
|
||||
github.com/valyala/fasttemplate v1.0.1/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
|
||||
github.com/valyala/fasttemplate v1.1.0 h1:RZqt0yGBsps8NGvLSGW804QQqCUYYLsaOjTVHy1Ocw4=
|
||||
github.com/valyala/fasttemplate v1.1.0/go.mod h1:UQGH1tvbgY+Nz5t2n7tXsz52dQxojPUpymEIMZ47gx8=
|
||||
github.com/valyala/fasttemplate v1.2.1 h1:TVEnxayobAdVkhQfrfes2IzOB6o+z4roRkPF52WA1u4=
|
||||
github.com/valyala/fasttemplate v1.2.1/go.mod h1:KHLXt3tVN2HBp8eijSv/kGJopbvo7S+qRAEEKiv+SiQ=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20190605123033-f99c8df09eb5/go.mod h1:yigFU9vqHzYiE8UmvKecakEJjdnWj3jj499lnFckfCI=
|
||||
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392 h1:ACG4HJsFiNMf47Y4PeRoebLNy/2lXT9EtprMuTFWt1M=
|
||||
golang.org/x/crypto v0.0.0-20190923035154-9ee001bba392/go.mod h1:/lpIB1dKB+9EgE3H3cr1v9wB50oz8l4C4h62xy7jSTY=
|
||||
golang.org/x/crypto v0.0.0-20191227163750-53104e6ec876/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20200128174031-69ecbb4d6d5d h1:9FCpayM9Egr1baVnV1SX0H87m+XB0B8S0hAMi99X/3U=
|
||||
golang.org/x/crypto v0.0.0-20200128174031-69ecbb4d6d5d/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a h1:vclmkQCjlDX5OydZ9wv8rBCcS0QyQY66Mpf/7BZbInM=
|
||||
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
|
||||
golang.org/x/net v0.0.0-20180218175443-cbe0f9307d01/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a h1:gOpx8G595UYyvj8UK4+OFyY4rx037g3fmfhe5SasG3U=
|
||||
@ -69,6 +112,11 @@ golang.org/x/net v0.0.0-20190923162816-aa69164e4478 h1:l5EDrHhldLYb3ZRHDUhXF7Om7
|
||||
golang.org/x/net v0.0.0-20190923162816-aa69164e4478/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553 h1:efeOvDhwQ29Dj3SdAV/MJf8oukgn+8D8WgaCaRMchF8=
|
||||
golang.org/x/net v0.0.0-20191209160850-c0dbc17a3553/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa h1:F+8P+gmewFQYRk6JoLQLwjBCTu3mcIURZfNkVweuRKA=
|
||||
golang.org/x/net v0.0.0-20200114155413-6afb5195e5aa/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200202094626-16171245cfb2/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s=
|
||||
golang.org/x/net v0.0.0-20200822124328-c89045814202 h1:VvcQYSHwXgi7W+TpUR6A9g6Up98WAHf3f/ulnJ62IyA=
|
||||
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f h1:wMNYb4v58l5UBM7MYRLPG6ZhfOqbKu7X5eyFl8ZhKvA=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
@ -81,13 +129,27 @@ golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5h
|
||||
golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190602015325-4c4f7f33c9ed/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190609082536-301114b31cce/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190813064441-fde4db37ae7a/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190922100055-0a153f010e69/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe h1:6fAMxZRR6sl1Uq8U61gxU+kPTs2tR8uOySCbBP7BN/M=
|
||||
golang.org/x/sys v0.0.0-20190924154521-2837fb4f24fe/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20191228213918-04cbcbbfeed8/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9 h1:1/DFK4b7JH8DmkqhUk48onnSfrPzImPoVxuomtbT2nk=
|
||||
golang.org/x/sys v0.0.0-20200124204421-9fbb57f87de9/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200323222414-85ca7c5b95cd/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200826173525-f9321e4c35a6 h1:DvY3Zkh7KabQE/kfzMvYvKirSiguP9Q/veMtkYyf0o8=
|
||||
golang.org/x/sys v0.0.0-20200826173525-f9321e4c35a6/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.2 h1:tW2bmiBqwgJj/UpqtC8EpXEZVYOwU0yG4iWbprSVAcs=
|
||||
golang.org/x/text v0.3.2/go.mod h1:bEr9sfX3Q8Zfm5fL9x+3itogRgK3+ptLWKqgva+5dAk=
|
||||
golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k=
|
||||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
|
||||
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324 h1:Hir2P/De0WpUhtrKGGjvSb2YxUgyZ7EFOSLIcSSpiwE=
|
||||
golang.org/x/time v0.0.0-20201208040808-7e3f01d25324/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190608022120-eacb66d2a7c3/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
|
||||
golang.org/x/tools v0.0.0-20190907020128-2ca718005c18/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo=
|
||||
@ -106,3 +168,10 @@ gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
s32x.com/ovrstat v0.0.0-20191125185405-f48c0d280dc1 h1:q5zjrLdxx3oo3i49aBKMMdppFoLCEEq6cSD8lWNCoAY=
|
||||
s32x.com/ovrstat v0.0.0-20191125185405-f48c0d280dc1/go.mod h1:UzsLSEoY8B4FByz4e+5GGKebJio+H+axo3RxLr7d7Mw=
|
||||
s32x.com/ovrstat v0.0.0-20200131231416-4cb42edd331d h1:G3p3gNYpF4WsklRFb4U2FWgXhicc2RDWgL+zNc//JWc=
|
||||
s32x.com/ovrstat v0.0.0-20200131231416-4cb42edd331d/go.mod h1:UzsLSEoY8B4FByz4e+5GGKebJio+H+axo3RxLr7d7Mw=
|
||||
s32x.com/ovrstat v0.0.0-20201003203341-5f1ad8502a8f/go.mod h1:UzsLSEoY8B4FByz4e+5GGKebJio+H+axo3RxLr7d7Mw=
|
||||
s32x.com/ovrstat v0.0.0-20201019064501-7679355452e1 h1:Ppeg8R00VA9EJ8n3owtEwy21vdGJPq/wJ7wLK0tElQA=
|
||||
s32x.com/ovrstat v0.0.0-20201019064501-7679355452e1/go.mod h1:M1e9y2Q2vUOaHRxB4l+vx3Dyje4HbaSls7L+dQ0PsEE=
|
||||
s32x.com/ovrstat v0.0.0-20210411215317-b668284adcc8 h1:UwvCWPAjUnC+BE2jlbozuYiiSfrJA5BtlkNdaMWUao0=
|
||||
s32x.com/ovrstat v0.0.0-20210411215317-b668284adcc8/go.mod h1:UJrvRJ1Rb0u6Croris6ZQQNQia+Yhu7JIM63uRyLOuc=
|
||||
|
118
main.go
118
main.go
@ -4,10 +4,14 @@ import (
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"flag"
|
||||
"fmt"
|
||||
"git.meow.tf/ow-api/ow-api/cache"
|
||||
"git.meow.tf/ow-api/ow-api/json-patch"
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"github.com/julienschmidt/httprouter"
|
||||
"github.com/rs/cors"
|
||||
"github.com/stoewer/go-strcase"
|
||||
"golang.org/x/net/context"
|
||||
"log"
|
||||
"net/http"
|
||||
"regexp"
|
||||
@ -17,12 +21,20 @@ import (
|
||||
)
|
||||
|
||||
const (
|
||||
Version = "2.3.1"
|
||||
Version = "2.4.6"
|
||||
|
||||
OpAdd = "add"
|
||||
OpRemove = "remove"
|
||||
)
|
||||
|
||||
type ApiVersion int
|
||||
|
||||
const (
|
||||
VersionOne ApiVersion = iota
|
||||
VersionTwo
|
||||
VersionThree
|
||||
)
|
||||
|
||||
type gamesStats struct {
|
||||
Played int64 `json:"played"`
|
||||
Won int64 `json:"won"`
|
||||
@ -115,41 +127,74 @@ func registerVersionTwo(router *httprouter.Router) {
|
||||
router.GET("/v2/stats/"+platform+"/:tag/heroes/:heroes", injectPlatform(platform, heroes))
|
||||
router.GET("/v2/stats/"+platform+"/:tag/profile", injectPlatform(platform, profile))
|
||||
router.GET("/v2/stats/"+platform+"/:tag/complete", injectPlatform(platform, stats))
|
||||
router.GET("/v3/stats/"+platform+"/:tag/heroes/:heroes", injectPlatform(platform, heroes))
|
||||
router.GET("/v3/stats/"+platform+"/:tag/profile", injectPlatform(platform, profile))
|
||||
router.GET("/v3/stats/"+platform+"/:tag/complete", injectPlatform(platform, stats))
|
||||
}
|
||||
|
||||
// Version
|
||||
router.GET("/v2/version", versionHandler)
|
||||
router.GET("/v3/version", versionHandler)
|
||||
}
|
||||
|
||||
func loadHeroNames() {
|
||||
stats, err := ovrstat.PCStats("cats-11481")
|
||||
res, err := http.Get("https://playoverwatch.com/en-us/heroes/")
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
m := make(map[string]bool)
|
||||
defer res.Body.Close()
|
||||
|
||||
for k := range stats.QuickPlayStats.TopHeroes {
|
||||
m[k] = true
|
||||
doc, err := goquery.NewDocumentFromReader(res.Body)
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
for k := range stats.QuickPlayStats.CareerStats {
|
||||
m[k] = true
|
||||
}
|
||||
links := doc.Find(".hero-portrait-detailed")
|
||||
|
||||
heroNames = make([]string, 0)
|
||||
|
||||
for k := range m {
|
||||
heroNames = append(heroNames, k)
|
||||
links.Each(func(_ int, s *goquery.Selection) {
|
||||
val, exists := s.Attr("data-hero-id")
|
||||
|
||||
if !exists {
|
||||
return
|
||||
}
|
||||
|
||||
heroNames = append(heroNames, strcase.LowerCamelCase(val))
|
||||
})
|
||||
|
||||
log.Println("Loaded heroes", heroNames)
|
||||
}
|
||||
|
||||
var (
|
||||
versionRegexp = regexp.MustCompile("^/(v\\d+)/")
|
||||
)
|
||||
|
||||
func injectPlatform(platform string, handler httprouter.Handle) httprouter.Handle {
|
||||
return func(w http.ResponseWriter, r *http.Request, ps httprouter.Params) {
|
||||
ps = append(ps, httprouter.Param{Key: "platform", Value: platform})
|
||||
|
||||
handler(w, r, ps)
|
||||
ctx := context.Background()
|
||||
|
||||
m := versionRegexp.FindStringSubmatch(r.RequestURI)
|
||||
|
||||
if m != nil {
|
||||
version := VersionOne
|
||||
|
||||
switch m[1] {
|
||||
case "v2":
|
||||
version = VersionTwo
|
||||
case "v3":
|
||||
version = VersionThree
|
||||
}
|
||||
|
||||
ctx = context.WithValue(ctx, "version", version)
|
||||
}
|
||||
|
||||
handler(w, r.WithContext(ctx), ps)
|
||||
}
|
||||
}
|
||||
|
||||
@ -157,15 +202,21 @@ var (
|
||||
tagRegexp = regexp.MustCompile("-(\\d+)$")
|
||||
)
|
||||
|
||||
func statsResponse(w http.ResponseWriter, ps httprouter.Params, patch *jsonpatch.Patch) ([]byte, error) {
|
||||
func statsResponse(w http.ResponseWriter, r *http.Request, ps httprouter.Params, patch *jsonpatch.Patch) ([]byte, error) {
|
||||
var stats *ovrstat.PlayerStats
|
||||
var err error
|
||||
|
||||
version := VersionOne
|
||||
|
||||
if v := r.Context().Value("version"); v != nil {
|
||||
version = v.(ApiVersion)
|
||||
}
|
||||
|
||||
tag := ps.ByName("tag")
|
||||
|
||||
tag = strings.Replace(tag, "#", "-", -1)
|
||||
|
||||
cacheKey := generateCacheKey(ps)
|
||||
cacheKey := generateCacheKey(r, ps)
|
||||
|
||||
platform := ps.ByName("platform")
|
||||
|
||||
@ -262,11 +313,36 @@ func statsResponse(w http.ResponseWriter, ps httprouter.Params, patch *jsonpatch
|
||||
iconUrl = rating.RankIcon
|
||||
}
|
||||
|
||||
rating = int(totalRating / len(stats.Ratings))
|
||||
rating = totalRating / len(stats.Ratings)
|
||||
|
||||
urlBase := iconUrl[0 : strings.Index(iconUrl, "rank-icons/")+11]
|
||||
|
||||
ratingIcon = urlBase + iconFor(rating)
|
||||
|
||||
if version == VersionThree {
|
||||
m := make(map[string]ovrstat.Rating)
|
||||
|
||||
ratingsPatches := make([]patchOperation, len(stats.Ratings))
|
||||
|
||||
for i, rating := range stats.Ratings {
|
||||
m[rating.Role] = rating
|
||||
ratingsPatches[i] = patchOperation{
|
||||
Op: OpRemove,
|
||||
Path: "/ratings/" + rating.Role + "/role",
|
||||
}
|
||||
}
|
||||
|
||||
extra = append(extra, patchOperation{
|
||||
Op: OpRemove,
|
||||
Path: "/ratings",
|
||||
}, patchOperation{
|
||||
Op: OpAdd,
|
||||
Path: "/ratings",
|
||||
Value: m,
|
||||
})
|
||||
|
||||
extra = append(extra, ratingsPatches...)
|
||||
}
|
||||
}
|
||||
|
||||
extra = append(extra, patchOperation{
|
||||
@ -330,6 +406,16 @@ func iconFor(rating int) string {
|
||||
return "rank-BronzeTier.png"
|
||||
}
|
||||
|
||||
func generateCacheKey(ps httprouter.Params) string {
|
||||
return ps.ByName("platform") + "-" + ps.ByName("tag")
|
||||
func generateCacheKey(r *http.Request, ps httprouter.Params) string {
|
||||
version := VersionOne
|
||||
|
||||
if v := r.Context().Value("version"); v != nil {
|
||||
version = v.(ApiVersion)
|
||||
}
|
||||
|
||||
return versionToString(version) + "-" + ps.ByName("platform") + "-" + ps.ByName("tag")
|
||||
}
|
||||
|
||||
func versionToString(version ApiVersion) string {
|
||||
return fmt.Sprintf("v%d", version)
|
||||
}
|
||||
|
@ -1,10 +1,12 @@
|
||||
fpm -s dir -t deb -p /build/$ARCH/owapi_${VERSION}_${ARCH}.deb \
|
||||
-n ow-api -v $VERSION \
|
||||
for arch in $(echo $ARCH | sed "s/,/ /g"); do
|
||||
fpm -s dir -t deb -p /build/owapi_${VERSION}_${arch}.deb \
|
||||
-n ow-api -v $VERSION -a $arch \
|
||||
--deb-priority optional --force \
|
||||
--deb-compression bzip2 \
|
||||
--deb-compression gz \
|
||||
--description "Overwatch API Server" \
|
||||
-m "Tyler Stuyfzand <admin@meow.tf>" --vendor "Meow.tf" \
|
||||
--before-install packaging/scripts/preinst.deb \
|
||||
--after-install packaging/scripts/postinst.deb \
|
||||
-a $ARCH /build/$ARCH/owapi_${ARCH}=/usr/bin/owapi \
|
||||
/build/owapi_linux_${arch}=/usr/bin/owapi \
|
||||
packaging/owapi.service=/lib/systemd/system/owapi.service
|
||||
done
|
@ -1 +1,3 @@
|
||||
curl -X POST "$UPLOAD_URL" -F "file_i386=@/build/i386/owapi_${VERSION}_i386.deb" -F "file_amd64=@/build/amd64/owapi_${VERSION}_amd64.deb" -F "file_armv7=@/build/armv7/owapi_${VERSION}_armv7.deb"
|
||||
curl -X POST "$UPLOAD_URL" -F "file_i386=@/build/i386/owapi_${VERSION}_i386.deb" \
|
||||
-F "file_amd64=@/build/amd64/owapi_${VERSION}_amd64.deb" \
|
||||
-F "file_armv7=@/build/armv7/owapi_${VERSION}_armv7.deb"
|
268
pro/main.go
Normal file
268
pro/main.go
Normal file
@ -0,0 +1,268 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/tls"
|
||||
"errors"
|
||||
"fmt"
|
||||
"github.com/PuerkitoBio/goquery"
|
||||
"github.com/miekg/dns"
|
||||
"log"
|
||||
"math/rand"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"s32x.com/ovrstat/ovrstat"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
func main() {
|
||||
cloudfrontUrl, err := lookupCloudfrontURL()
|
||||
|
||||
if err != nil {
|
||||
log.Fatalln("Unable to find url:", err)
|
||||
}
|
||||
|
||||
log.Println("URL:", cloudfrontUrl)
|
||||
|
||||
ips, err := lookupIpv6Dns(cloudfrontUrl)
|
||||
|
||||
if err != nil {
|
||||
log.Fatalln("Unable to find ips:", err)
|
||||
}
|
||||
|
||||
log.Println("IPs:", ips)
|
||||
|
||||
localIps, err := checkIpv6Local()
|
||||
|
||||
if err != nil {
|
||||
log.Fatalln("Unable to get local ips")
|
||||
}
|
||||
|
||||
log.Println("Local IPs:", localIps)
|
||||
|
||||
r := rand.New(rand.NewSource(time.Now().UnixNano()))
|
||||
|
||||
localAddr, err := net.ResolveIPAddr("ip", "")
|
||||
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// You also need to do this to make it work and not give you a
|
||||
// "mismatched local address type ip"
|
||||
// This will make the ResolveIPAddr a TCPAddr without needing to
|
||||
// say what SRC port number to use.
|
||||
localTCPAddr := net.TCPAddr{
|
||||
IP: localAddr.IP,
|
||||
}
|
||||
|
||||
defaultDialer := &net.Dialer{
|
||||
Timeout: 30 * time.Second,
|
||||
KeepAlive: 30 * time.Second,
|
||||
}
|
||||
|
||||
dialer := &net.Dialer{
|
||||
LocalAddr: &localTCPAddr,
|
||||
Timeout: 30 * time.Second,
|
||||
KeepAlive: 30 * time.Second,
|
||||
}
|
||||
|
||||
transport := &http.Transport{
|
||||
DialContext: func(ctx context.Context, network, addr string) (net.Conn, error) {
|
||||
oldNetwork := network
|
||||
oldAddr := addr
|
||||
|
||||
if addr == "playoverwatch.com:443" {
|
||||
network = "tcp6"
|
||||
addr = "[" + ips[r.Intn(len(ips))] + "]:443"
|
||||
}
|
||||
|
||||
log.Println("Dial using", addr)
|
||||
|
||||
c, err := dialer.DialContext(ctx, network, addr)
|
||||
|
||||
if err != nil {
|
||||
log.Println("Fallback")
|
||||
c, err = defaultDialer.DialContext(ctx, oldNetwork, oldAddr)
|
||||
}
|
||||
|
||||
return c, err
|
||||
},
|
||||
TLSClientConfig: &tls.Config{
|
||||
ServerName: "playoverwatch.com",
|
||||
},
|
||||
}
|
||||
|
||||
http.DefaultClient = &http.Client{
|
||||
Transport: transport,
|
||||
}
|
||||
|
||||
stats, err := ovrstat.PCStats("cats-11481")
|
||||
|
||||
if err != nil {
|
||||
log.Fatalln("Error retrieving:", err)
|
||||
}
|
||||
|
||||
log.Println(stats.Name+" is level", stats.Level)
|
||||
}
|
||||
|
||||
func lookupCloudfrontURL() (string, error) {
|
||||
res, err := http.Get("https://playoverwatch.com/en-us/")
|
||||
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
|
||||
defer res.Body.Close()
|
||||
|
||||
doc, err := goquery.NewDocumentFromReader(res.Body)
|
||||
|
||||
links := doc.Find("link").Map(func(i int, s *goquery.Selection) string {
|
||||
v, exists := s.Attr("href")
|
||||
|
||||
if !exists {
|
||||
return ""
|
||||
}
|
||||
|
||||
return v
|
||||
})
|
||||
|
||||
for _, link := range links {
|
||||
u, err := url.Parse(link)
|
||||
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
if strings.HasSuffix(u.Host, "cloudfront.net") {
|
||||
return u.Host, nil
|
||||
}
|
||||
}
|
||||
|
||||
return "", errors.New("no cloudfront url")
|
||||
}
|
||||
|
||||
func lookupIpv6Dns(host string) ([]string, error) {
|
||||
c := &dns.Client{
|
||||
Net: "udp",
|
||||
}
|
||||
|
||||
msg := new(dns.Msg)
|
||||
msg.Id = dns.Id()
|
||||
msg.RecursionDesired = true
|
||||
msg.Question = make([]dns.Question, 1)
|
||||
msg.Question[0] = dns.Question{Name: dns.Fqdn(host), Qtype: dns.TypeAAAA, Qclass: dns.ClassINET}
|
||||
|
||||
in, _, err := c.Exchange(msg, "8.8.8.8:53")
|
||||
|
||||
result := make([]string, 0)
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
if in != nil && in.Rcode != dns.RcodeSuccess {
|
||||
return result, errors.New(dns.RcodeToString[in.Rcode])
|
||||
}
|
||||
|
||||
for _, record := range in.Answer {
|
||||
if t, ok := record.(*dns.AAAA); ok {
|
||||
result = append(result, t.AAAA.String())
|
||||
}
|
||||
}
|
||||
return result, err
|
||||
}
|
||||
|
||||
func checkIpv6Local() ([]string, error) {
|
||||
ifaces, err := net.Interfaces()
|
||||
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ret := make([]string, 0)
|
||||
|
||||
for _, i := range ifaces {
|
||||
addrs, err := i.Addrs()
|
||||
|
||||
if err != nil {
|
||||
continue
|
||||
}
|
||||
|
||||
for _, addr := range addrs {
|
||||
var ip net.IP
|
||||
|
||||
switch v := addr.(type) {
|
||||
case *net.IPNet:
|
||||
ip = v.IP
|
||||
case *net.IPAddr:
|
||||
ip = v.IP
|
||||
}
|
||||
|
||||
log.Println("Check", ip.String())
|
||||
|
||||
if ip == nil || ip.To4() == nil || isPrivateIP(ip) {
|
||||
continue
|
||||
}
|
||||
|
||||
log.Println("Checking", ip.String())
|
||||
|
||||
if ipnet, ok := addr.(*net.IPNet); ok {
|
||||
for ip := ipnet.IP.Mask(ipnet.Mask); ipnet.Contains(ip); inc(ip) {
|
||||
ret = append(ret, ip.String())
|
||||
}
|
||||
|
||||
continue
|
||||
}
|
||||
|
||||
ret = append(ret, ip.String())
|
||||
}
|
||||
}
|
||||
|
||||
return ret, nil
|
||||
}
|
||||
|
||||
func inc(ip net.IP) {
|
||||
for j := len(ip) - 1; j >= 0; j-- {
|
||||
ip[j]++
|
||||
if ip[j] > 0 {
|
||||
break
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
var privateIPBlocks []*net.IPNet
|
||||
|
||||
func init() {
|
||||
for _, cidr := range []string{
|
||||
"127.0.0.0/8", // IPv4 loopback
|
||||
"10.0.0.0/8", // RFC1918
|
||||
"172.16.0.0/12", // RFC1918
|
||||
"192.168.0.0/16", // RFC1918
|
||||
"169.254.0.0/16", // RFC3927 link-local
|
||||
"::1/128", // IPv6 loopback
|
||||
"fe80::/10", // IPv6 link-local
|
||||
"fc00::/7", // IPv6 unique local addr
|
||||
} {
|
||||
_, block, err := net.ParseCIDR(cidr)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("parse error on %q: %v", cidr, err))
|
||||
}
|
||||
privateIPBlocks = append(privateIPBlocks, block)
|
||||
}
|
||||
}
|
||||
|
||||
func isPrivateIP(ip net.IP) bool {
|
||||
if ip.IsLoopback() || ip.IsLinkLocalUnicast() || ip.IsLinkLocalMulticast() {
|
||||
return true
|
||||
}
|
||||
|
||||
for _, block := range privateIPBlocks {
|
||||
if block.Contains(ip) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
@ -7,12 +7,13 @@ import (
|
||||
"log"
|
||||
"net/http"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
const (
|
||||
baseURL = "https://playoverwatch.com/en-us/career"
|
||||
|
||||
apiURL = "https://playoverwatch.com/en-us/career/platforms/"
|
||||
apiURL = "https://playoverwatch.com/en-us/search/account-by-name/"
|
||||
)
|
||||
|
||||
type Platform struct {
|
||||
@ -86,20 +87,12 @@ func ValidateEndpoint() error {
|
||||
return err
|
||||
}
|
||||
|
||||
code, err := pd.Html()
|
||||
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
split := careerInitRegexp.FindStringSubmatch(code)
|
||||
|
||||
if split == nil || len(split) < 2 {
|
||||
return errNoCareerInit
|
||||
}
|
||||
|
||||
// Validate API response
|
||||
if err := validateApi(split[1]); err != nil {
|
||||
if err := validateApi(strings.Replace(url[strings.LastIndex(url, "/")+1:], "-", "%23", -1)); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
@ -155,12 +148,12 @@ func validateCareerStats(careerStatsSelector *goquery.Selection, parent string)
|
||||
|
||||
selectors := []string{
|
||||
"div.row div.js-stats", // Top level
|
||||
"div.row div.js-stats div.column.xs-12", // stat boxes
|
||||
"div.row div.js-stats div.column.xs-12 .stat-title", // stat boxes
|
||||
"div.row div.js-stats div.column.xs-12 table.DataTable", // data table
|
||||
"div.row div.js-stats div.column.xs-12 table.DataTable tbody", // data table tbody
|
||||
"div.row div.js-stats div.column.xs-12 table.DataTable tbody tr", // data table tbody tr
|
||||
"div.row div.js-stats div.column.xs-12 table.DataTable tbody tr td", // data table tbody tr td
|
||||
"div.row div.js-stats div.column", // stat boxes
|
||||
"div.row div.js-stats div.column .stat-title", // stat boxes
|
||||
"div.row div.js-stats div.column table.DataTable", // data table
|
||||
"div.row div.js-stats div.column table.DataTable tbody", // data table tbody
|
||||
"div.row div.js-stats div.column table.DataTable tbody tr", // data table tbody tr
|
||||
"div.row div.js-stats div.column table.DataTable tbody tr td", // data table tbody tr td
|
||||
}
|
||||
|
||||
return validateElementsExist(careerStatsSelector, parent, selectors...)
|
||||
|
Reference in New Issue
Block a user