-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactoring to a library and a command.
- Loading branch information
Showing
6 changed files
with
112 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,5 @@ | ||
FROM alpine:latest | ||
|
||
RUN mkdir /usr/local/septabot | ||
WORKDIR /usr/local/septabot | ||
COPY bin/septa /usr/local/bin/septa | ||
|
||
COPY bin/septabot /usr/local/bin/septabot | ||
|
||
EXPOSE 8080 | ||
ENTRYPOINT ["/usr/local/bin/septabot"] | ||
|
||
CMD ["--help"] | ||
CMD septa |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
# go-septa | ||
Septa alerting slack bot | ||
# septa | ||
Septa command line for getting the next to arrive. | ||
|
||
## Commands | ||
|
||
### septa nta <src> <dest> | ||
### septa next <src> <dest> | ||
Returns the next to arrive between the src and dest stations. | ||
|
||
### septa stations | ||
TODO: will list the stations. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package septa | ||
|
||
import "time" | ||
|
||
// Client is used to make calls to the septa website. | ||
type Client struct { | ||
|
||
// Domain is the api domain. | ||
Domain string | ||
|
||
// Timeout is the number of seconds before the call times out. | ||
Timeout time.Duration | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"fmt" | ||
) | ||
|
||
// NextToArrive takes a "from" station name and a "to" station name and returns the expected trains. | ||
func NextToArrive(ctx context.Context) { | ||
from := flag.Arg(1) | ||
to := flag.Arg(2) | ||
fmt.Printf("from=%v to=%v\n", from, to) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
package main | ||
|
||
import ( | ||
"context" | ||
"flag" | ||
"fmt" | ||
) | ||
|
||
var funcMap map[string]func(context.Context) | ||
|
||
func init() { | ||
funcMap = map[string]func(context.Context){ | ||
"help": Usage, | ||
"next": NextToArrive, | ||
} | ||
} | ||
|
||
// Usage prints how to invoke `septa` from the command line. | ||
func Usage(ctx context.Context) { | ||
fmt.Printf(` | ||
Usage: | ||
septa next [from-station] [to-station] | ||
`) | ||
|
||
} | ||
|
||
func main() { | ||
flag.Parse() | ||
|
||
ctx := context.Background() | ||
|
||
command := flag.Arg(0) | ||
if command == "" || command == "help" { | ||
Usage(ctx) | ||
return | ||
} | ||
|
||
f := funcMap[command] | ||
if f == nil { | ||
fmt.Println("Unknown command") | ||
Usage(ctx) | ||
return | ||
} | ||
|
||
f(ctx) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,32 +1,44 @@ | ||
.PHONY: * | ||
.PHONY: all clean pull get build build-in-container image | ||
|
||
GOLANG = golang:1.10 | ||
GOOS = darwin | ||
GOLANG := golang:1.13 | ||
GOOS := darwin | ||
|
||
all: clean pull build septaimage | ||
all: clean pull lint sec build install | ||
|
||
clean: | ||
rm -rf vendor/ | ||
mkdir -p bin | ||
rm -f bin/septabot bin/narb bin/sub || true | ||
rm -f bin/septa || true | ||
|
||
get: | ||
mkdir -p vendor | ||
|
||
pull: | ||
docker pull ${GOLANG} | ||
|
||
lint: | ||
docker run -i --rm -v ${PWD}:/go/src/github.com/dherbst/septa -w /go/src/github.com/dherbst/septa ${GOLANG} make lint-in-container | ||
|
||
lint-in-container: | ||
go get -u golang.org/x/lint/golint | ||
golint github.com/dherbst/septa | ||
golint github.com/dherbst/septa/cmd/septa/... | ||
|
||
sec: | ||
docker run -it --rm -v ${PWD}:/go/src/github.com/dherbst/septa -w /go/src/github.com/dherbst/septa ${GOLANG} make sec-in-container | ||
|
||
sec-in-container: | ||
go get -u github.com/securego/gosec/cmd/gosec | ||
gosec . | ||
|
||
build: | ||
docker run -i --rm -v "$(PWD)":/usr/src/myapp -w /usr/src/myapp ${GOLANG} make build-in-container | ||
docker run -i --rm -v "$(PWD)":/go/src/github.com/dherbst/septa -w /go/src/github.com/dherbst/septa ${GOLANG} make build-in-container | ||
|
||
build-in-container: | ||
GOPATH=/usr/src/myapp go vet septabot | ||
GOPATH=/usr/src/myapp go test -coverprofile=coverage.out septabot | ||
GOPATH=/usr/src/myapp go tool cover -html=coverage.out -o coverage.html | ||
GOOS=${GOOS} GOPATH=/usr/src/myapp go build -o bin/septabot /usr/src/myapp/src/septabot/cmd/septabot/septabot.go | ||
GOOS=${GOOS} GOPATH=/usr/src/myapp go build -o bin/septa /usr/src/myapp/src/septabot/cmd/septa/septa.go | ||
GOOS=${GOOS} GOPATH=/usr/src/myapp go build -o bin/narb /usr/src/myapp/src/septabot/cmd/narb/narb.go | ||
GOOS=${GOOS} GOPATH=/usr/src/myapp go build -o bin/sub /usr/src/myapp/src/septabot/cmd/sub/sub.go | ||
|
||
GOOS=darwin go build -o bin/septa cmd/septa/*.go | ||
|
||
septaimage: build | ||
docker build -t septabot:latest . | ||
install: | ||
cp bin/septa ~/bin/septa | ||
|
||
run: | ||
docker run -p 8080:8080 -d septabot:latest | ||
image: build | ||
docker build -t septa:latest . |