Compare commits

...

16 Commits

Author SHA1 Message Date
Greg Gauthier c2508127b4 package updates 2023-12-13 12:00:28 +00:00
Greg Gauthier d0a8fdfb11 add buildpath and platform to the downloader 2021-03-19 09:15:37 +00:00
Greg Gauthier 8a78251c05 add buildpath and platform to the downloader 2021-03-19 09:12:31 +00:00
Greg Gauthier 00c8b76fe0 add buildpath to the downloader 2021-03-19 09:08:01 +00:00
Greg Gauthier 27a7d9f60b add buildpath to the downloader 2021-03-19 09:05:48 +00:00
Greg Gauthier 027d922916 add platform name to version string 2021-03-19 08:47:56 +00:00
Greg Gauthier 758d317d0f add platform spec to build path;echo version to console 2021-03-19 08:45:56 +00:00
Greg Gauthier 44080ebac9 ignore the go.sum. every time a build occurs this changes. No need to capture, if the build is always going to generate this anyway 2021-03-19 08:02:02 +00:00
Greg Gauthier 0fa518cd00 don't assume gopath is set 2021-03-19 07:54:29 +00:00
Greg Gauthier b2a096a956 Merge branch 'master' of bitbucket.org:gmgauthier_ecs/gostations 2021-03-19 07:34:37 +00:00
Greg Gauthier 419372c49d Merge branch 'master' of github.com:gmgauthier/gostations 2021-03-19 07:34:12 +00:00
Greg Gauthier 370876db38 add binary download to the downloads page 2021-03-18 18:42:35 +00:00
Greg Gauthier be14b434fc for some reason, bitbucket doesn't like the cover option 2021-03-18 08:05:47 +00:00
Greg Gauthier 39d1baf41b add coverage reporting 2021-03-18 07:54:02 +00:00
Greg Gauthier e67d973c2f clean up test and build step. makes more sense now. 2021-03-18 07:52:33 +00:00
Greg Gauthier 9dd8ef46bd activate testing steps 2021-03-18 07:33:35 +00:00
5 changed files with 36 additions and 59 deletions

1
.gitignore vendored
View File

@ -2,3 +2,4 @@
build/
vendor/
*.iml
go.sum

View File

@ -1,8 +1,3 @@
# Template Go (Golang) build
# This template allows you to validate your Go (Golang) code.
# The workflow allows running tests, build and code linting on the default branch.
image: golang:1.15
pipelines:
@ -11,13 +6,14 @@ pipelines:
- step:
name: Test and Build
script:
#- mkdir test-reports
#- go get -u github.com/jstemmer/go-junit-report
#- go test tests/* -v 2>&1 | go-junit-report > test-reports/report.xml
- mkdir build
- go mod vendor
- go mod tidy
- go build -o build/gostations github.com/gmgauthier/gostations
- go test -v
- mkdir build
- ./build.sh
- export BUILDPATH="build/$(uname)/gostations"
- curl -X POST --user "${BITBUCKET_USERNAME}:${BITBUCKET_APP_PASSWORD}" "https://api.bitbucket.org/2.0/repositories/${BITBUCKET_REPO_OWNER}/${BITBUCKET_REPO_SLUG}/downloads" --form files=@"${BUILDPATH}"
- step:
name: Lint code
image: golangci/golangci-lint:v1.31.0

View File

@ -3,6 +3,7 @@ package main
import (
"encoding/json"
"fmt"
"io"
"log"
"math/rand"
"net"
@ -12,17 +13,17 @@ import (
)
type stationRecord struct {
Name string `json:"name"`
Codec string `json:"codec"`
Name string `json:"name"`
Codec string `json:"codec"`
Bitrate json.Number `json:"bitrate"`
Countrycode string `json:"countrycode"`
Tags string `json:"tags"`
Url string `json:"url"`
Lastcheck int `json:"lastcheckok"`
Countrycode string `json:"countrycode"`
Tags string `json:"tags"`
Url string `json:"url"`
Lastcheck int `json:"lastcheckok"`
}
func RandomIP(iplist []net.IP) net.IP {
rand.Seed(time.Now().Unix())
rand.NewSource(time.Now().Unix())
randomIndex := rand.Intn(len(iplist))
return iplist[randomIndex]
}
@ -44,13 +45,18 @@ func GetApiHost() string {
return apiHost
}
func GetStations(qstring string) ([]stationRecord, error){
urlstr := fmt.Sprintf("https://%s/json/stations/search?%s&limit=%d",GetApiHost(),qstring,maxitems())
func GetStations(qstring string) ([]stationRecord, error) {
urlstr := fmt.Sprintf("https://%s/json/stations/search?%s&limit=%d", GetApiHost(), qstring, maxitems())
resp, err := http.Get(urlstr)
if err != nil {
log.Print(err.Error())
}
defer resp.Body.Close()
defer func(Body io.ReadCloser) {
err := Body.Close()
if err != nil {
log.Print(err.Error())
}
}(resp.Body)
var data []stationRecord
err = json.NewDecoder(resp.Body).Decode(&data)
@ -72,28 +78,26 @@ func pruneStations(stations []stationRecord) []stationRecord {
func StationSearch(name string, country string, state string, tags string, notok bool) ([]stationRecord, error) {
params := url.Values{}
if name != ""{
if name != "" {
params.Add("name", name)
}
if country != "" {
params.Add("country", country)
}
if state != ""{
if state != "" {
params.Add("state", state)
}
if tags != ""{
params.Add("tag",tags)
if tags != "" {
params.Add("tag", tags)
}
stations, err := GetStations(params.Encode())
if err != nil{
if err != nil {
return nil, err
}
if notok{
if notok {
return stations, err
} // otherwise prune the list
prunedStations := pruneStations(stations) // eliminate stations that are reporting down.
return prunedStations, err
}

View File

@ -1,16 +1,21 @@
#!/usr/bin/env sh
GOPATH=$HOME/go
GOPATH=$GOPATH:$(pwd)
export GOPATH
GIT_COMMIT=$(git rev-list -1 HEAD)
export GIT_COMMIT
CANONICAL_VERSION=$(cat ./VERSION)
CANONICAL_VERSION=$(cat ./VERSION)-$(uname)
export CANONICAL_VERSION
VERSION_STRING="$CANONICAL_VERSION-$GIT_COMMIT"
export VERSION_STRING
buildpath="build/$(uname)/gostations"
go mod vendor
go mod tidy
go build -o build/gostations -ldflags "-X main.version=$VERSION_STRING"
go build -o "$buildpath" -ldflags "-X main.version=$VERSION_STRING"
"$buildpath" -v

29
go.sum
View File

@ -1,29 +0,0 @@
github.com/alyu/configparser v0.0.0-20191103060215-744e9a66e7bc h1:eN2FUvn4J1A31pICABioDYukoh1Tmlei6L3ImZUin/I=
github.com/alyu/configparser v0.0.0-20191103060215-744e9a66e7bc/go.mod h1:BYq/NZTroWuzkvsTPJgRBqSHGxKMHCz06gtlfY/W5RU=
github.com/davecgh/go-spew v1.1.0 h1:ZDRjVQ15GmhC3fiQ8ni8+OwkZQO4DARzQgrnXU1Liz8=
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/daviddengcn/go-colortext v0.0.0-20180409174941-186a3d44e920 h1:d/cVoZOrJPJHKH1NdeUjyVAWKp4OpOT+Q+6T1sH7jeU=
github.com/daviddengcn/go-colortext v0.0.0-20180409174941-186a3d44e920/go.mod h1:dv4zxwHi5C/8AeI+4gX4dCWOIvNi7I6JCSX0HvlKPgE=
github.com/dixonwille/wlog/v3 v3.0.1 h1:ViTSsNNndHlKW5S89x5O0KSTpTT9zdPqrkA/TZYY8+s=
github.com/dixonwille/wlog/v3 v3.0.1/go.mod h1:fPYZR9Ne5gFh3N8b3CuXVWHWxkY6Yg1wCeS3Km6Nc0I=
github.com/dixonwille/wmenu/v5 v5.1.0 h1:sKBHDoQ945NRvK0Eitd0kHDYHl1IYOSr1sdCK9c+Qr0=
github.com/dixonwille/wmenu/v5 v5.1.0/go.mod h1:l6EGfXHaN6DPgv5+V5RY+cydAXJsj/oDZVczcdukPzc=
github.com/golangplus/bytes v0.0.0-20160111154220-45c989fe5450 h1:7xqw01UYS+KCI25bMrPxwNYkSns2Db1ziQPpVq99FpE=
github.com/golangplus/bytes v0.0.0-20160111154220-45c989fe5450/go.mod h1:Bk6SMAONeMXrxql8uvOKuAZSu8aM5RUGv+1C6IJaEho=
github.com/golangplus/fmt v0.0.0-20150411045040-2a5d6d7d2995 h1:f5gsjBiF9tRRVomCvrkGMMWI8W1f2OBFar2c5oakAP0=
github.com/golangplus/fmt v0.0.0-20150411045040-2a5d6d7d2995/go.mod h1:lJgMEyOkYFkPcDKwRXegd+iM6E7matEszMG5HhwytU8=
github.com/golangplus/testing v0.0.0-20180327235837-af21d9c3145e h1:KhcknUwkWHKZPbFy2P7jH5LKJ3La+0ZeknkkmrSgqb0=
github.com/golangplus/testing v0.0.0-20180327235837-af21d9c3145e/go.mod h1:0AA//k/eakGydO4jKRoRL2j92ZKSzTgj9tclaCrvXHk=
github.com/mattn/go-isatty v0.0.11 h1:FxPOTFNqGkuDUGi3H/qkUbQO4ZiBa2brKq5r0l8TGeM=
github.com/mattn/go-isatty v0.0.11/go.mod h1:PhnuNfih5lzO57/f3n+odYbM4JtupLOxQOAqxQCu2WE=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
github.com/stretchr/testify v1.4.0 h1:2E4SXV/wtOkTonXsotYi4li6zVWxYlZuYNCXe9XRJyk=
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037 h1:YyJpGZS1sBuBCzLAR1VEpK193GlqGZbnPFnPV/5Rsb4=
golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=