Skip to content

Commit fdb2d72

Browse files
author
Jan Stamer
committed
Initial Commit
0 parents  commit fdb2d72

23 files changed

+499
-0
lines changed

.buffalo.dev.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
app_root: .
2+
ignored_folders:
3+
- vendor
4+
- log
5+
- logs
6+
- assets
7+
- public
8+
- grifts
9+
- tmp
10+
- bin
11+
- node_modules
12+
- .sass-cache
13+
included_extensions:
14+
- .go
15+
- .env
16+
build_path: tmp
17+
build_delay: 200ns
18+
binary_name: go_buffalo_turbo-build
19+
command_flags: []
20+
enable_colors: true
21+
log_name: buffalo

.codeclimate.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
version: "2"
2+
checks:
3+
method-lines:
4+
config:
5+
threshold: 100
6+
plugins:
7+
fixme:
8+
enabled: true
9+
gofmt:
10+
enabled: true
11+
golint:
12+
enabled: true
13+
govet:
14+
enabled: true
15+
exclude_patterns:
16+
- grifts/**/*
17+
- "**/*_test.go"
18+
- "*_test.go"
19+
- "**_test.go"
20+
- logs/*
21+
- public/*
22+
- templates/*
23+
- "**/node_modules/"

.dockerignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
node_modules/
2+
*.log
3+
bin/

.gitignore

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
vendor/
2+
**/*.log
3+
**/*.sqlite
4+
.idea/
5+
bin/
6+
tmp/
7+
node_modules/
8+
.sass-cache/
9+
*-packr.go
10+
public/assets/
11+
.vscode/
12+
.grifter/
13+
.env
14+
**/.DS_Store
15+
*.pid
16+
coverage
17+
coverage.data
18+
.svn
19+
.console_history
20+
.sass-cache/*
21+
.jhw-cache/
22+
jhw.*
23+
*.sublime*
24+
dist/
25+
generated/
26+
.vendor/
27+

Dockerfile

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
# This is a multi-stage Dockerfile and requires >= Docker 17.05
2+
# https://docs.docker.com/engine/userguide/eng-image/multistage-build/
3+
FROM gobuffalo/buffalo:v0.16.18 as builder
4+
5+
ENV GO111MODULE on
6+
ENV GOPROXY http://proxy.golang.org
7+
8+
RUN mkdir -p /src/go_buffalo_turbo
9+
WORKDIR /src/go_buffalo_turbo
10+
11+
# Copy the Go Modules manifests
12+
COPY go.mod go.mod
13+
COPY go.sum go.sum
14+
# cache deps before building and copying source so that we don't need to re-download as much
15+
# and so that source changes don't invalidate our downloaded layer
16+
RUN go mod download
17+
18+
ADD . .
19+
RUN buffalo build --static -o /bin/app
20+
21+
FROM alpine
22+
RUN apk add --no-cache bash
23+
RUN apk add --no-cache ca-certificates
24+
25+
WORKDIR /bin/
26+
27+
COPY --from=builder /bin/app .
28+
29+
# Uncomment to run the binary in "production" mode:
30+
# ENV GO_ENV=production
31+
32+
# Bind the app to 0.0.0.0 so it can be seen from outside the container
33+
ENV ADDR=0.0.0.0
34+
35+
EXPOSE 3000
36+
37+
# Uncomment to run the migrations before running the binary:
38+
# CMD /bin/app migrate; /bin/app
39+
CMD exec /bin/app

README.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# Welcome to Buffalo!
2+
3+
Thank you for choosing Buffalo for your web development needs.
4+
5+
## Starting the Application
6+
7+
Buffalo ships with a command that will watch your application and automatically rebuild the Go binary and any assets for you. To do that run the "buffalo dev" command:
8+
9+
$ buffalo dev
10+
11+
If you point your browser to [http://127.0.0.1:3000](http://127.0.0.1:3000) you should see a "Welcome to Buffalo!" page.
12+
13+
**Congratulations!** You now have your Buffalo application up and running.
14+
15+
## What Next?
16+
17+
We recommend you heading over to [http://gobuffalo.io](http://gobuffalo.io) and reviewing all of the great documentation there.
18+
19+
Good luck!
20+
21+
[Powered by Buffalo](http://gobuffalo.io)

actions/actions_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package actions
2+
3+
import (
4+
"testing"
5+
6+
"github.com/gobuffalo/packr/v2"
7+
"github.com/gobuffalo/suite"
8+
)
9+
10+
type ActionSuite struct {
11+
*suite.Action
12+
}
13+
14+
func Test_ActionSuite(t *testing.T) {
15+
action, err := suite.NewActionWithFixtures(App(), packr.New("Test_ActionSuite", "../fixtures"))
16+
if err != nil {
17+
t.Fatal(err)
18+
}
19+
20+
as := &ActionSuite{
21+
Action: action,
22+
}
23+
suite.Run(t, as)
24+
}

actions/app.go

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package actions
2+
3+
import (
4+
"github.com/gobuffalo/buffalo"
5+
"github.com/gobuffalo/envy"
6+
forcessl "github.com/gobuffalo/mw-forcessl"
7+
paramlogger "github.com/gobuffalo/mw-paramlogger"
8+
"github.com/unrolled/secure"
9+
10+
csrf "github.com/gobuffalo/mw-csrf"
11+
i18n "github.com/gobuffalo/mw-i18n"
12+
"github.com/gobuffalo/packr/v2"
13+
)
14+
15+
// ENV is used to help switch settings based on where the
16+
// application is being run. Default is "development".
17+
var ENV = envy.Get("GO_ENV", "development")
18+
var app *buffalo.App
19+
var T *i18n.Translator
20+
21+
// App is where all routes and middleware for buffalo
22+
// should be defined. This is the nerve center of your
23+
// application.
24+
//
25+
// Routing, middleware, groups, etc... are declared TOP -> DOWN.
26+
// This means if you add a middleware to `app` *after* declaring a
27+
// group, that group will NOT have that new middleware. The same
28+
// is true of resource declarations as well.
29+
//
30+
// It also means that routes are checked in the order they are declared.
31+
// `ServeFiles` is a CATCH-ALL route, so it should always be
32+
// placed last in the route declarations, as it will prevent routes
33+
// declared after it to never be called.
34+
func App() *buffalo.App {
35+
if app == nil {
36+
app = buffalo.New(buffalo.Options{
37+
Env: ENV,
38+
SessionName: "_go_buffalo_turbo_session",
39+
})
40+
41+
// Automatically redirect to SSL
42+
app.Use(forceSSL())
43+
44+
// Log request parameters (filters apply).
45+
app.Use(paramlogger.ParameterLogger)
46+
47+
// Protect against CSRF attacks. https://www.owasp.org/index.php/Cross-Site_Request_Forgery_(CSRF)
48+
// Remove to disable this.
49+
app.Use(csrf.New)
50+
51+
// Setup and use translations:
52+
app.Use(translations())
53+
54+
app.GET("/", HomeHandler)
55+
56+
app.ServeFiles("/", assetsBox) // serve files from the public directory
57+
}
58+
59+
return app
60+
}
61+
62+
// translations will load locale files, set up the translator `actions.T`,
63+
// and will return a middleware to use to load the correct locale for each
64+
// request.
65+
// for more information: https://gobuffalo.io/en/docs/localization
66+
func translations() buffalo.MiddlewareFunc {
67+
var err error
68+
if T, err = i18n.New(packr.New("app:locales", "../locales"), "en-US"); err != nil {
69+
app.Stop(err)
70+
}
71+
return T.Middleware()
72+
}
73+
74+
// forceSSL will return a middleware that will redirect an incoming request
75+
// if it is not HTTPS. "http://example.com" => "https://example.com".
76+
// This middleware does **not** enable SSL. for your application. To do that
77+
// we recommend using a proxy: https://gobuffalo.io/en/docs/proxy
78+
// for more information: https://github.com/unrolled/secure/
79+
func forceSSL() buffalo.MiddlewareFunc {
80+
return forcessl.Middleware(secure.Options{
81+
SSLRedirect: ENV == "production",
82+
SSLProxyHeaders: map[string]string{"X-Forwarded-Proto": "https"},
83+
})
84+
}

actions/home.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
package actions
2+
3+
import (
4+
"net/http"
5+
6+
"github.com/gobuffalo/buffalo"
7+
)
8+
9+
// HomeHandler is a default handler to serve up
10+
// a home page.
11+
func HomeHandler(c buffalo.Context) error {
12+
return c.Render(http.StatusOK, r.HTML("index.html"))
13+
}

actions/home_test.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package actions
2+
3+
import "net/http"
4+
5+
func (as *ActionSuite) Test_HomeHandler() {
6+
res := as.HTML("/").Get()
7+
8+
as.Equal(http.StatusOK, res.Code)
9+
as.Contains(res.Body.String(), "Welcome to Buffalo")
10+
}

0 commit comments

Comments
 (0)