Skip to content
This repository was archived by the owner on Mar 22, 2022. It is now read-only.

Commit 74b74e7

Browse files
author
Jasper Berghoef
committed
Various updates
1 parent 977d513 commit 74b74e7

File tree

6 files changed

+110
-16
lines changed

6 files changed

+110
-16
lines changed

Dockerfile

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
1-
FROM golang:1.9.2
1+
FROM golang:1.10.3
2+
3+
ENV PROTOCOL=https
4+
ENV ORIGIN=www.example.com
25

36
WORKDIR /go/src/app
47
COPY . .
58

6-
RUN go-wrapper download
7-
RUN go-wrapper install
9+
RUN go get -d -v ./...
10+
RUN go install -v ./...
11+
RUN go build .
812

9-
CMD ["go-wrapper", "run"]
13+
CMD ["app"]

Gopkg.lock

Lines changed: 33 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Gopkg.toml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# Gopkg.toml example
2+
#
3+
# Refer to https://github.com/golang/dep/blob/master/docs/Gopkg.toml.md
4+
# for detailed Gopkg.toml documentation.
5+
#
6+
# required = ["github.com/user/thing/cmd/thing"]
7+
# ignored = ["github.com/user/project/pkgX", "bitbucket.org/user/project/pkgA/pkgY"]
8+
#
9+
# [[constraint]]
10+
# name = "github.com/user/project"
11+
# version = "1.0.0"
12+
#
13+
# [[constraint]]
14+
# name = "github.com/user/project2"
15+
# branch = "dev"
16+
# source = "github.com/myfork/project2"
17+
#
18+
# [[override]]
19+
# name = "github.com/x/y"
20+
# version = "2.4.0"
21+
#
22+
# [prune]
23+
# non-go = false
24+
# go-tests = true
25+
# unused-packages = true
26+
27+
28+
[[constraint]]
29+
name = "github.com/boltdb/bolt"
30+
version = "1.3.1"
31+
32+
[[constraint]]
33+
name = "github.com/carlescere/scheduler"
34+
version = "0.1.0"
35+
36+
[[constraint]]
37+
name = "gopkg.in/kyokomi/emoji.v1"
38+
version = "1.5.1"
39+
40+
[prune]
41+
go-tests = true
42+
unused-packages = true

Makefile

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
all: reset install test build
22

33
build:
4-
go build *.go
4+
go build -o gocdn *.go
55

66
test:
77
go test -v
@@ -10,8 +10,7 @@ reset:
1010
rm -rf cache cache.db
1111

1212
install:
13-
go get -d -v
14-
go install -v
13+
dep ensure
1514

1615
docker_build:
1716
docker build -t gocdn .

cdn.go

Lines changed: 24 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ import (
88
"os"
99
"path/filepath"
1010

11+
"encoding/json"
12+
1113
"github.com/boltdb/bolt"
1214
"github.com/carlescere/scheduler"
1315
emoji "gopkg.in/kyokomi/emoji.v1"
14-
"encoding/json"
1516
)
1617

1718
var protocol = flag.String("protocol", "", "The protocol used by your website.")
@@ -92,19 +93,30 @@ func init() {
9293
return
9394
}
9495
}
95-
}
9696

97-
/* main
98-
Spins up the awesomeness.
99-
================================================================================ */
100-
func main() {
10197
flag.Parse()
10298

99+
if *protocol == "" {
100+
*protocol = os.Getenv("PROTOCOL")
101+
}
102+
103+
if *origin == "" {
104+
*origin = os.Getenv("ORIGIN")
105+
}
106+
103107
if *protocol == "" || *origin == "" {
104-
fmt.Println("Please provide a protocol and origin.\nUse '--help' for more information.")
108+
fmt.Println(`
109+
Please provide a protocol and origin.\n
110+
Use '--help' for more information.
111+
`)
105112
return
106113
}
114+
}
107115

116+
/* main
117+
Spins up the awesomeness.
118+
================================================================================ */
119+
func main() {
108120
// Open database
109121
var err error
110122
db, err = bolt.Open("cache.db", 0600, nil)
@@ -121,10 +133,14 @@ func main() {
121133
return nil
122134
})
123135

136+
scheduler.Every(5).Minutes().Run(cleanCache)
137+
124138
// Start HTTP server
125139
http.HandleFunc("/", requestHandler)
126140

127-
switch{
141+
fmt.Println("Listening on port", ":8080")
142+
143+
switch {
128144
case *protocol == "http":
129145
http.ListenAndServe(":8080", nil)
130146
case *protocol == "https":

controller_storage.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ func verifyAndRetrieveFile(localFile string, originURL string) {
6060
}
6161

6262
relPath, _ := filepath.Rel(cacheDir, localFile)
63-
emoji.Println("\t:truck: Retreiving file:", originURL, "\n\t:memo: Writing", n, "bytes to", relPath)
63+
emoji.Println("\t:truck: Retrieving file:", originURL, "\n\t:memo: Writing", n, "bytes to", relPath)
6464

6565
go registerFileToDb(originURL, relPath, maxAge, revalidate, response.Header)
6666

0 commit comments

Comments
 (0)