Skip to content

Commit bfe3b8b

Browse files
author
randith
committed
added stats accumulation to getHash endpoit, added comments to README
1 parent 2f65212 commit bfe3b8b

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

README.md

+20-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,24 @@
11
# goexample
22

3-
## getting started
3+
## notes
4+
1. I included a build script to make a docker container from the PoC I did recently. It is very early in development but a good first step to a real ci/cd build of a go service. It is not complete, missing among other things versioning."
5+
2. I started running short on time so I did not add tests for 4-6. I would add these as well as a round-trip test using the endpoints.
6+
3. I interpreted step 6 "hash requests" to include creating and getting the hashes
7+
4. I left TODO comments in the code to shed light on my thoughts. I do not like leaving them in the code normally as they grow stale fast.
8+
9+
## running
10+
1. prerequisites
11+
* docker
12+
* this repository installed properly in the GOPATH
13+
* being in the root directory of this repository
14+
2. execute build script
15+
* ```./build.sh```
16+
3. run container
17+
* ```docker run -p 8080:8080 pwhash```
18+
19+
## developing
20+
21+
### setting up go environment
422

523
1. install go and dep
624
* ```brew install go dep```
@@ -15,9 +33,8 @@
1533
3. get this service
1634
* ```go get github.com/randith/goexample```
1735

18-
## developing
19-
2036
### add or update dependencies
37+
Of course there are none yet since only using standard libraries
2138

2239
* ```dep ensure```
2340
* commit and push dependencies

cmd/pwhash/main.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ func startHttpServer(store pwhash.Store, statsStore pwhash.Stats) *http.Server {
2323
srv := &http.Server{Addr: ":8080"}
2424

2525
http.Handle("/hash", pwhash.PostHashHandler(store, statsStore))
26-
http.Handle("/hash/", pwhash.GetHashHandler(store))
26+
http.Handle("/hash/", pwhash.GetHashHandler(store, statsStore))
2727
http.Handle("/shutdown", pwhash.PostShutdownHandler(srv))
2828
http.Handle("/stats", pwhash.GetStatsHandler(statsStore))
2929

pkg/pwhash/getHash.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"time"
99
)
1010

11-
func GetHashHandler(store Store) http.Handler {
11+
func GetHashHandler(store Store, stats Stats) http.Handler {
1212
return http.HandlerFunc(func(rw http.ResponseWriter, req *http.Request) {
1313
start := time.Now()
1414
if req.Method != "GET" {
@@ -34,6 +34,8 @@ func GetHashHandler(store Store) http.Handler {
3434
rw.Header().Set("Content-Type", "text/plain")
3535
io.WriteString(rw, hash)
3636

37-
log.Printf("GetHashHandler complete in %s", time.Now().Sub(start))
37+
duration := time.Now().Sub(start)
38+
stats.Time(duration.Nanoseconds() / int64(time.Millisecond))
39+
log.Printf("GetHashHandler complete in %s", duration)
3840
})
3941
}

0 commit comments

Comments
 (0)