Skip to content

Commit 24f6cdd

Browse files
author
Jan Stamer
committed
Initial Commit
0 parents  commit 24f6cdd

28 files changed

+1749
-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: gobuff-realworld-example-app-build
19+
command_flags: []
20+
enable_colors: true
21+
log_name: buffalo

.codeclimate.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
engines:
2+
fixme:
3+
enabled: true
4+
gofmt:
5+
enabled: true
6+
golint:
7+
enabled: true
8+
govet:
9+
enabled: true
10+
exclude_paths:
11+
- grifts/**/*
12+
- "**/*_test.go"
13+
- "*_test.go"
14+
- "**_test.go"
15+
- logs/*
16+
- public/*
17+
- templates/*
18+
ratings:
19+
paths:
20+
- "**.go"

.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: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
node_modules/
25+
dist/
26+
generated/
27+
.vendor/
28+

Dockerfile

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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.14.4 as builder
4+
5+
RUN mkdir -p $GOPATH/src/gobuff_realworld_example_app
6+
WORKDIR $GOPATH/src/gobuff_realworld_example_app
7+
8+
ADD . .
9+
ENV GO111MODULES=on
10+
RUN go get ./...
11+
RUN buffalo build --static -o /bin/app
12+
13+
FROM alpine
14+
RUN apk add --no-cache bash
15+
RUN apk add --no-cache ca-certificates
16+
17+
WORKDIR /bin/
18+
19+
COPY --from=builder /bin/app .
20+
21+
# Uncomment to run the binary in "production" mode:
22+
# ENV GO_ENV=production
23+
24+
# Bind the app to 0.0.0.0 so it can be seen from outside the container
25+
ENV ADDR=0.0.0.0
26+
27+
EXPOSE 3000
28+
29+
# Uncomment to run the migrations before running the binary:
30+
# CMD /bin/app migrate; /bin/app
31+
CMD exec /bin/app

README.md

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
# Welcome to Buffalo!
2+
3+
Thank you for choosing Buffalo for your web development needs.
4+
5+
## Database Setup
6+
7+
It looks like you chose to set up your application using a database! Fantastic!
8+
9+
The first thing you need to do is open up the "database.yml" file and edit it to use the correct usernames, passwords, hosts, etc... that are appropriate for your environment.
10+
11+
You will also need to make sure that **you** start/install the database of your choice. Buffalo **won't** install and start it for you.
12+
13+
### Create Your Databases
14+
15+
Ok, so you've edited the "database.yml" file and started your database, now Buffalo can create the databases in that file for you:
16+
17+
$ buffalo pop create -a
18+
19+
## Starting the Application
20+
21+
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:
22+
23+
$ buffalo dev
24+
25+
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.
26+
27+
**Congratulations!** You now have your Buffalo application up and running.
28+
29+
## What Next?
30+
31+
We recommend you heading over to [http://gobuffalo.io](http://gobuffalo.io) and reviewing all of the great documentation there.
32+
33+
Good luck!
34+
35+
[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: 92 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,92 @@
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+
"gobuff_realworld_example_app/models"
11+
12+
"github.com/gobuffalo/buffalo-pop/pop/popmw"
13+
csrf "github.com/gobuffalo/mw-csrf"
14+
i18n "github.com/gobuffalo/mw-i18n"
15+
"github.com/gobuffalo/packr/v2"
16+
)
17+
18+
// ENV is used to help switch settings based on where the
19+
// application is being run. Default is "development".
20+
var ENV = envy.Get("GO_ENV", "development")
21+
var app *buffalo.App
22+
var T *i18n.Translator
23+
24+
// App is where all routes and middleware for buffalo
25+
// should be defined. This is the nerve center of your
26+
// application.
27+
//
28+
// Routing, middleware, groups, etc... are declared TOP -> DOWN.
29+
// This means if you add a middleware to `app` *after* declaring a
30+
// group, that group will NOT have that new middleware. The same
31+
// is true of resource declarations as well.
32+
//
33+
// It also means that routes are checked in the order they are declared.
34+
// `ServeFiles` is a CATCH-ALL route, so it should always be
35+
// placed last in the route declarations, as it will prevent routes
36+
// declared after it to never be called.
37+
func App() *buffalo.App {
38+
if app == nil {
39+
app = buffalo.New(buffalo.Options{
40+
Env: ENV,
41+
SessionName: "_gobuff_realworld_example_app_session",
42+
})
43+
44+
// Automatically redirect to SSL
45+
app.Use(forceSSL())
46+
47+
// Log request parameters (filters apply).
48+
app.Use(paramlogger.ParameterLogger)
49+
50+
// Protect against CSRF attacks. https://www.owasp.org/index.php/Cross-Site_Request_Forgery_(CSRF)
51+
// Remove to disable this.
52+
app.Use(csrf.New)
53+
54+
// Wraps each request in a transaction.
55+
// c.Value("tx").(*pop.Connection)
56+
// Remove to disable this.
57+
app.Use(popmw.Transaction(models.DB))
58+
59+
// Setup and use translations:
60+
app.Use(translations())
61+
62+
app.GET("/", HomeHandler)
63+
64+
app.ServeFiles("/", assetsBox) // serve files from the public directory
65+
}
66+
67+
return app
68+
}
69+
70+
// translations will load locale files, set up the translator `actions.T`,
71+
// and will return a middleware to use to load the correct locale for each
72+
// request.
73+
// for more information: https://gobuffalo.io/en/docs/localization
74+
func translations() buffalo.MiddlewareFunc {
75+
var err error
76+
if T, err = i18n.New(packr.New("app:locales", "../locales"), "en-US"); err != nil {
77+
app.Stop(err)
78+
}
79+
return T.Middleware()
80+
}
81+
82+
// forceSSL will return a middleware that will redirect an incoming request
83+
// if it is not HTTPS. "http://example.com" => "https://example.com".
84+
// This middleware does **not** enable SSL. for your application. To do that
85+
// we recommend using a proxy: https://gobuffalo.io/en/docs/proxy
86+
// for more information: https://github.com/unrolled/secure/
87+
func forceSSL() buffalo.MiddlewareFunc {
88+
return forcessl.Middleware(secure.Options{
89+
SSLRedirect: ENV == "production",
90+
SSLProxyHeaders: map[string]string{"X-Forwarded-Proto": "https"},
91+
})
92+
}

actions/home.go

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

actions/home_test.go

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

0 commit comments

Comments
 (0)