Skip to content

Commit

Permalink
Initial Commit
Browse files Browse the repository at this point in the history
  • Loading branch information
noobnoobdc137 committed Jul 17, 2020
0 parents commit 9b2aeae
Show file tree
Hide file tree
Showing 18 changed files with 363 additions and 0 deletions.
21 changes: 21 additions & 0 deletions .buffalo.dev.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
app_root: .
ignored_folders:
- vendor
- log
- logs
- assets
- public
- grifts
- tmp
- bin
- node_modules
- .sass-cache
included_extensions:
- .go
- .env
build_path: tmp
build_delay: 200ns
binary_name: simple-api-build
command_flags: []
enable_colors: true
log_name: buffalo
23 changes: 23 additions & 0 deletions .codeclimate.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
version: "2"
checks:
method-lines:
config:
threshold: 100
plugins:
fixme:
enabled: true
gofmt:
enabled: true
golint:
enabled: true
govet:
enabled: true
exclude_patterns:
- grifts/**/*
- "**/*_test.go"
- "*_test.go"
- "**_test.go"
- logs/*
- public/*
- templates/*
- "**/node_modules/"
3 changes: 3 additions & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
node_modules/
*.log
bin/
27 changes: 27 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
vendor/
**/*.log
**/*.sqlite
.idea/
bin/
tmp/
node_modules/
.sass-cache/
*-packr.go
public/assets/
.vscode/
.grifter/
.env
**/.DS_Store
*.pid
coverage
coverage.data
.svn
.console_history
.sass-cache/*
.jhw-cache/
jhw.*
*.sublime*
dist/
generated/
.vendor/

39 changes: 39 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
# This is a multi-stage Dockerfile and requires >= Docker 17.05
# https://docs.docker.com/engine/userguide/eng-image/multistage-build/
FROM gobuffalo/buffalo:v0.16.12 as builder

ENV GO111MODULE on
ENV GOPROXY http://proxy.golang.org

RUN mkdir -p /src/trying-buffalo
WORKDIR /src/trying-buffalo

# Copy the Go Modules manifests
COPY go.mod go.mod
COPY go.sum go.sum
# cache deps before building and copying source so that we don't need to re-download as much
# and so that source changes don't invalidate our downloaded layer
RUN go mod download

ADD . .
RUN buffalo build --static -o /bin/app

FROM alpine
RUN apk add --no-cache bash
RUN apk add --no-cache ca-certificates

WORKDIR /bin/

COPY --from=builder /bin/app .

# Uncomment to run the binary in "production" mode:
# ENV GO_ENV=production

# Bind the app to 0.0.0.0 so it can be seen from outside the container
ENV ADDR=0.0.0.0

EXPOSE 3000

# Uncomment to run the migrations before running the binary:
# CMD /bin/app migrate; /bin/app
CMD exec /bin/app
21 changes: 21 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# Welcome to Buffalo!

Thank you for choosing Buffalo for your web development needs.

## Starting the Application

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:

$ buffalo dev

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.

**Congratulations!** You now have your Buffalo application up and running.

## What Next?

We recommend you heading over to [http://gobuffalo.io](http://gobuffalo.io) and reviewing all of the great documentation there.

Good luck!

[Powered by Buffalo](http://gobuffalo.io)
24 changes: 24 additions & 0 deletions actions/actions_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package actions

import (
"testing"

"github.com/gobuffalo/packr/v2"
"github.com/gobuffalo/suite"
)

type ActionSuite struct {
*suite.Action
}

func Test_ActionSuite(t *testing.T) {
action, err := suite.NewActionWithFixtures(App(), packr.New("Test_ActionSuite", "../fixtures"))
if err != nil {
t.Fatal(err)
}

as := &ActionSuite{
Action: action,
}
suite.Run(t, as)
}
69 changes: 69 additions & 0 deletions actions/app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package actions

import (
"github.com/gobuffalo/buffalo"
"github.com/gobuffalo/envy"
forcessl "github.com/gobuffalo/mw-forcessl"
paramlogger "github.com/gobuffalo/mw-paramlogger"
"github.com/unrolled/secure"

contenttype "github.com/gobuffalo/mw-contenttype"
"github.com/gobuffalo/x/sessions"
"github.com/rs/cors"
)

// ENV is used to help switch settings based on where the
// application is being run. Default is "development".
var ENV = envy.Get("GO_ENV", "development")
var app *buffalo.App

// App is where all routes and middleware for buffalo
// should be defined. This is the nerve center of your
// application.
//
// Routing, middleware, groups, etc... are declared TOP -> DOWN.
// This means if you add a middleware to `app` *after* declaring a
// group, that group will NOT have that new middleware. The same
// is true of resource declarations as well.
//
// It also means that routes are checked in the order they are declared.
// `ServeFiles` is a CATCH-ALL route, so it should always be
// placed last in the route declarations, as it will prevent routes
// declared after it to never be called.
func App() *buffalo.App {
if app == nil {
app = buffalo.New(buffalo.Options{
Env: ENV,
SessionStore: sessions.Null{},
PreWares: []buffalo.PreWare{
cors.Default().Handler,
},
SessionName: "_simple_api_session",
})

// Automatically redirect to SSL
app.Use(forceSSL())

// Log request parameters (filters apply).
app.Use(paramlogger.ParameterLogger)

// Set the request content type to JSON
app.Use(contenttype.Set("application/json"))

app.GET("/", HomeHandler)
}

return app
}

// forceSSL will return a middleware that will redirect an incoming request
// if it is not HTTPS. "http://example.com" => "https://example.com".
// This middleware does **not** enable SSL. for your application. To do that
// we recommend using a proxy: https://gobuffalo.io/en/docs/proxy
// for more information: https://github.com/unrolled/secure/
func forceSSL() buffalo.MiddlewareFunc {
return forcessl.Middleware(secure.Options{
SSLRedirect: ENV == "production",
SSLProxyHeaders: map[string]string{"X-Forwarded-Proto": "https"},
})
}
13 changes: 13 additions & 0 deletions actions/home.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package actions

import (
"net/http"

"github.com/gobuffalo/buffalo"
)

// HomeHandler is a default handler to serve up
// a home page.
func HomeHandler(c buffalo.Context) error {
return c.Render(http.StatusOK, r.JSON(map[string]string{"message": "Welcome to Buffalo!"}))
}
10 changes: 10 additions & 0 deletions actions/home_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package actions

import "net/http"

func (as *ActionSuite) Test_HomeHandler() {
res := as.JSON("/").Get()

as.Equal(http.StatusOK, res.Code)
as.Contains(res.Body.String(), "Welcome to Buffalo")
}
13 changes: 13 additions & 0 deletions actions/render.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package actions

import (
"github.com/gobuffalo/buffalo/render"
)

var r *render.Engine

func init() {
r = render.New(render.Options{
DefaultContentType: "application/json",
})
}
13 changes: 13 additions & 0 deletions config/buffalo-app.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name = "simple-api"
bin = "bin\\simple-api"
vcs = "git"
with_pop = false
with_sqlite = false
with_dep = false
with_webpack = false
with_nodejs = false
with_yarn = false
with_docker = true
with_grifts = true
as_web = false
as_api = true
Empty file added config/buffalo-plugins.toml
Empty file.
32 changes: 32 additions & 0 deletions fixtures/sample.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
[[scenario]]
name = "lots of widgets"

[[scenario.table]]
name = "widgets"

[[scenario.table.row]]
id = "<%= uuidNamed("widget") %>"
name = "This is widget #1"
body = "some widget body"
created_at = "<%= now() %>"
updated_at = "<%= now() %>"

[[scenario.table.row]]
id = "<%= uuid() %>"
name = "This is widget #2"
body = "some widget body"
created_at = "<%= now() %>"
updated_at = "<%= now() %>"

[[scenario.table]]
name = "users"

[[scenario.table.row]]
id = "<%= uuid() %>"
name = "Mark Bates"
admin = true
age = 41
widget_id = "<%= uuidNamed("widget") %>"
created_at = "<%= now() %>"
updated_at = "<%= now() %>"

3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module simple_api

go 1.14
11 changes: 11 additions & 0 deletions grifts/init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package grifts

import (
"simple_api/actions"

"github.com/gobuffalo/buffalo"
)

func init() {
buffalo.Grifts(actions.App())
}
3 changes: 3 additions & 0 deletions inflections.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"singular": "plural"
}
38 changes: 38 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package main

import (
"log"

"simple_api/actions"
)

// main is the starting point for your Buffalo application.
// You can feel free and add to this `main` method, change
// what it does, etc...
// All we ask is that, at some point, you make sure to
// call `app.Serve()`, unless you don't want to start your
// application that is. :)
func main() {
app := actions.App()
if err := app.Serve(); err != nil {
log.Fatal(err)
}
}

/*
# Notes about `main.go`
## SSL Support
We recommend placing your application behind a proxy, such as
Apache or Nginx and letting them do the SSL heavy lifting
for you. https://gobuffalo.io/en/docs/proxy
## Buffalo Build
When `buffalo build` is run to compile your binary, this `main`
function will be at the heart of that binary. It is expected
that your `main` function will start your application using
the `app.Serve()` method.
*/

0 comments on commit 9b2aeae

Please sign in to comment.