forked from gomods/athens
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Proposal: move buffalo app to cmd (gomods#91)
* buffalo app moved to cmd * ooops: * added copy of proxy as olympus * removed buffalo test * added blank endpoint for feed * forgot db config file and storage setup * resolved comments * newlines * resolved conficts
- Loading branch information
1 parent
e76125d
commit 9c14b1f
Showing
239 changed files
with
13,791 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
build: | ||
buffalo build | ||
cd cmd/proxy && buffalo build | ||
|
||
run: build | ||
./athens | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
{ | ||
"presets": ["env"] | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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: olympus-build | ||
command_flags: [] | ||
enable_colors: true | ||
log_name: buffalo |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# 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.11.0 as builder | ||
|
||
RUN mkdir -p $GOPATH/src/github.com/gomods/athens/cmd/olympus | ||
WORKDIR $GOPATH/src/github.com/gomods/athens/cmd/olympus | ||
|
||
# this will cache the npm install step, unless package.json changes | ||
ADD cmd/olympus/package.json . | ||
ADD cmd/olympus/yarn.lock . | ||
RUN yarn install --no-progress | ||
|
||
WORKDIR $GOPATH/src/github.com/gomods/athens | ||
|
||
ADD . . | ||
RUN cd cmd/olympus && buffalo build -s -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 . | ||
|
||
# Comment out 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 | ||
|
||
# Comment out to run the migrations before running the binary: | ||
# CMD /bin/app migrate; /bin/app | ||
CMD exec /bin/app |
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package actions | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/gobuffalo/buffalo" | ||
"github.com/gobuffalo/buffalo/middleware" | ||
"github.com/gobuffalo/buffalo/middleware/ssl" | ||
"github.com/gobuffalo/envy" | ||
"github.com/rs/cors" | ||
"github.com/unrolled/secure" | ||
|
||
"github.com/gobuffalo/buffalo/middleware/csrf" | ||
"github.com/gobuffalo/buffalo/middleware/i18n" | ||
"github.com/gobuffalo/packr" | ||
) | ||
|
||
// 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 | ||
|
||
// T is buffalo Translator | ||
var T *i18n.Translator | ||
|
||
// App is where all routes and middleware for buffalo | ||
// should be defined. This is the nerve center of your | ||
// application. | ||
func App() *buffalo.App { | ||
if app == nil { | ||
app = buffalo.New(buffalo.Options{ | ||
Env: ENV, | ||
PreWares: []buffalo.PreWare{ | ||
cors.Default().Handler, | ||
}, | ||
SessionName: "_olympus_session", | ||
}) | ||
// Automatically redirect to SSL | ||
app.Use(ssl.ForceSSL(secure.Options{ | ||
SSLRedirect: ENV == "production", | ||
SSLProxyHeaders: map[string]string{"X-Forwarded-Proto": "https"}, | ||
})) | ||
|
||
if ENV == "development" { | ||
app.Use(middleware.ParameterLogger) | ||
} | ||
initializeTracing(app) | ||
// Protect against CSRF attacks. https://www.owasp.org/index.php/Cross-Site_Request_Forgery_(CSRF) | ||
// Remove to disable this. | ||
csrfMiddleware := csrf.New | ||
app.Use(csrfMiddleware) | ||
|
||
// Wraps each request in a transaction. | ||
// c.Value("tx").(*pop.PopTransaction) | ||
// Remove to disable this. | ||
// app.Use(middleware.PopTransaction(models.DB)) | ||
|
||
// Setup and use translations: | ||
var err error | ||
if T, err = i18n.New(packr.NewBox("../locales"), "en-US"); err != nil { | ||
app.Stop(err) | ||
} | ||
app.Use(T.Middleware()) | ||
|
||
storage, err := newStorage() | ||
if err != nil { | ||
log.Fatalf("error creating storage (%s)", err) | ||
return nil | ||
} | ||
|
||
app.GET("/", homeHandler) | ||
app.GET("/feed/{syncpoint:.*}", feedHandler(storage)) | ||
|
||
app.ServeFiles("/", assetsBox) // serve files from the public directory | ||
} | ||
|
||
return app | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package actions | ||
|
||
import ( | ||
"net/http" | ||
|
||
"github.com/gobuffalo/buffalo" | ||
"github.com/gomods/athens/pkg/storage" | ||
) | ||
|
||
func feedHandler(s storage.Backend) func(c buffalo.Context) error { | ||
return func(c buffalo.Context) error { | ||
if _, err := getSyncPoint(c); err != nil { | ||
return err | ||
} | ||
|
||
feed := make(map[string][]string) | ||
|
||
return c.Render(http.StatusOK, olympus.JSON(feed)) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package actions | ||
|
||
import ( | ||
"github.com/gobuffalo/buffalo" | ||
) | ||
|
||
func homeHandler(c buffalo.Context) error { | ||
return c.Render(200, olympus.HTML("index.html")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package actions | ||
|
||
import ( | ||
"github.com/gobuffalo/buffalo" | ||
) | ||
|
||
func getSyncPoint(c buffalo.Context) (string, error) { | ||
syncpoint := c.Param("syncpoint") | ||
if syncpoint == "" { | ||
return "", nil | ||
} | ||
return syncpoint, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package actions | ||
|
||
import ( | ||
"github.com/gobuffalo/buffalo/render" | ||
"github.com/gobuffalo/packr" | ||
) | ||
|
||
var olympus *render.Engine | ||
var assetsBox = packr.NewBox("../public") | ||
|
||
func init() { | ||
olympus = render.New(render.Options{ | ||
// HTML layout to be used for all HTML requests: | ||
HTMLLayout: "application.html", | ||
JavaScriptLayout: "application.js", | ||
|
||
// Box containing all of the templates: | ||
TemplatesBox: packr.NewBox("../templates/olympus"), | ||
AssetsBox: assetsBox, | ||
|
||
// Add template helpers here: | ||
Helpers: render.Helpers{}, | ||
}) | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/gomods/athens/cmd/olympus/actions" | ||
) | ||
|
||
func main() { | ||
app := actions.App() | ||
if err := app.Serve(); err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<div class="row mt-5"> | ||
<div class="col text-center"> | ||
<h1>Welcome to GopherPacks.io</h1> | ||
<p> This is where gods resides </p> | ||
</div> | ||
</div> |
Binary file not shown.
Binary file not shown.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
{ | ||
"presets": ["env"] | ||
} | ||
|
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package actions | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/gobuffalo/suite" | ||
) | ||
|
||
type ActionSuite struct { | ||
*suite.Action | ||
} | ||
|
||
func Test_ActionSuite(t *testing.T) { | ||
as := &ActionSuite{suite.NewAction(App())} | ||
suite.Run(t, as) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Oops, something went wrong.