Skip to content

Commit

Permalink
Merge pull request #18 from Shpota/dependencies
Browse files Browse the repository at this point in the history
Updated dependencies & documentation
  • Loading branch information
Shpota authored Feb 19, 2020
2 parents 4f5728b + b5725e1 commit 2f0fc1a
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 60 deletions.
42 changes: 18 additions & 24 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
# goxygen [![build](https://github.com/Shpota/goxygen/workflows/build/badge.svg)](https://github.com/Shpota/goxygen/actions?query=workflow%3Abuild) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://github.com/Shpota/goxygen/pulls)
# goxygen [![build](https://github.com/Shpota/goxygen/workflows/build/badge.svg)](https://github.com/Shpota/goxygen/actions?query=workflow%3Abuild) [![](https://badges.gitter.im/goxygen/community.svg)](https://gitter.im/goxygen/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) [![PRs Welcome](https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square)](https://github.com/Shpota/goxygen/pulls)

<img src="./templates/webapp/src/logo.svg" align="right" width="230px" alt="goxygen logo">

**Generate a Full Stack Web project with Go, React, and MongoDB in seconds.**

Goxygen aims at saving your time while setting up a new project. It
creates a skeleton of an application with all configuration done for
you. You can start implementing your business logic strait away.
you. You can start implementing your business logic straight away.
Goxygen generates back end Go code, connects it with front end React
components, provides a Dockerfile for the application and creates
docker-compose files for convenient run in development and production
environments.

## How to use
You need to have Go 1.11 or newer on your machine.
```go
go get -u github.com/shpota/goxygen
go run github.com/shpota/goxygen init my-app
```
This creates a new `my-app` project folder. The generated project
is ready to run with `docker-compose`:
This generates a project in `my-app` folder.

The generated project is ready to run with `docker-compose`:
```sh
cd my-app
docker-compose up
```
After the build is completed, the application is accessible
on http://localhost:8080.

You can find more details on how to work with the generated
project in its readme file.

![Showcase](.github/showcase.gif)

## Structure of a generated project
Expand Down Expand Up @@ -55,28 +60,17 @@ on http://localhost:8080.
├── .gitignore
└── README.md # guide on how to use the generated repo

Files such as unit tests or sample components are not reflected here
Files such as unit tests or sample components are not included here
for simplicity.

## Toolchain

You need to have [Go](https://golang.org/) installed to generate
a project with Goxygen.

In order to work with the generated project you need to have
[Go](https://golang.org/), [Node.js](https://nodejs.org/),
[Docker](https://www.docker.com/),
and [Docker Compose](https://docs.docker.com/compose/)
(comes pre-installed with Docker on Mac and Windows).
## Dependencies

Verify the toolchain by running the following commands:

```sh
go version
npm --version
docker --version
docker-compose --version
```
Goxygen generates a basic structure of a project and doesn't force you
to use a specific set of tools. That's why it doesn't bring unneeded
dependencies to your project. The only two dependencies are
[mongo-go-driver](https://github.com/mongodb/mongo-go-driver) on the
back end side and [axios](https://github.com/axios/axios) on the front
end side.

## How to contribute

Expand All @@ -88,6 +82,6 @@ You can also propose your changes via a Pull Request. Fork the
repository, make changes, send us a pull request and we'll
review it shortly.

### Logo
### Credits
Goxygen's logo was created by [Egon Elbre](https://twitter.com/egonelbre).

39 changes: 21 additions & 18 deletions static/generated.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ webapp/node_modules
webapp/build
webapp/npm-debug.log*
`,
"Dockerfile": `FROM node:12.15 AS JS_BUILD
"Dockerfile": `FROM node:12.16 AS JS_BUILD
COPY webapp /webapp
WORKDIR webapp
RUN npm install && npm run build --prod
FROM golang:1.13.7-alpine AS GO_BUILD
FROM golang:1.13.8-alpine AS GO_BUILD
RUN apk add build-base
COPY server /server
WORKDIR /server
Expand Down Expand Up @@ -60,6 +60,10 @@ docker --version
docker-compose --version
` + "`" + `` + "`" + `` + "`" + `
If you are using Windows you will also need
[gcc](https://gcc.gnu.org/). It comes installed
on Mac and almost all Linux distributions.
## Start in development mode
In the project directory run the command (you might
Expand Down Expand Up @@ -102,7 +106,7 @@ its database. Access the application on http://localhost:8080.
"docker-compose-dev.yml": `version: "3.7"
services:
dev_db:
image: mongo:4.2.2
image: mongo:4.2.3
environment:
MONGO_INITDB_DATABASE: tech
ports:
Expand All @@ -122,7 +126,7 @@ services:
environment:
profile: prod
db:
image: mongo:4.2.2
image: mongo:4.2.3
container_name: db
environment:
MONGO_INITDB_DATABASE: tech
Expand Down Expand Up @@ -184,10 +188,7 @@ func (m MongoDB) GetTechnologies() ([]*model.Technology, error) {
go 1.13
require (
github.com/gorilla/mux v1.7.3
go.mongodb.org/mongo-driver v1.2.1
)
require go.mongodb.org/mongo-driver v1.3.0
`,
"server/model/technology.go": `package model
Expand Down Expand Up @@ -236,34 +237,36 @@ func clientOptions() *options.ClientOptions {
import (
"encoding/json"
"github.com/gorilla/mux"
"log"
"net/http"
"project-name/db"
)
type App struct {
d db.DB
r *mux.Router
d db.DB
handlers map[string]http.HandlerFunc
}
func NewApp(d db.DB, cors bool) App {
app := App{
d: d,
r: mux.NewRouter(),
d: d,
handlers: make(map[string]http.HandlerFunc),
}
handler := app.GetTechnologies
techHandler := app.GetTechnologies
if !cors {
handler = disableCors(handler)
techHandler = disableCors(techHandler)
}
app.r.HandleFunc("/api/technologies", handler).Methods("GET")
app.r.PathPrefix("/").Handler(http.FileServer(http.Dir("/webapp")))
app.handlers["/api/technologies"] = techHandler
app.handlers["/"] = http.FileServer(http.Dir("/webapp")).ServeHTTP
return app
}
func (a *App) Serve() error {
for path, handler := range a.handlers {
http.Handle(path, handler)
}
log.Println("Web server is available on port 8080")
return http.ListenAndServe(":8080", a.r)
return http.ListenAndServe(":8080", nil)
}
func (a *App) GetTechnologies(w http.ResponseWriter, r *http.Request) {
Expand Down
4 changes: 2 additions & 2 deletions templates/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
FROM node:12.15 AS JS_BUILD
FROM node:12.16 AS JS_BUILD
COPY webapp /webapp
WORKDIR webapp
RUN npm install && npm run build --prod

FROM golang:1.13.7-alpine AS GO_BUILD
FROM golang:1.13.8-alpine AS GO_BUILD
RUN apk add build-base
COPY server /server
WORKDIR /server
Expand Down
4 changes: 4 additions & 0 deletions templates/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@ docker --version
docker-compose --version
```

If you are using Windows you will also need
[gcc](https://gcc.gnu.org/). It comes installed
on Mac and almost all Linux distributions.

## Start in development mode

In the project directory run the command (you might
Expand Down
2 changes: 1 addition & 1 deletion templates/docker-compose-dev.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
version: "3.7"
services:
dev_db:
image: mongo:4.2.2
image: mongo:4.2.3
environment:
MONGO_INITDB_DATABASE: tech
ports:
Expand Down
2 changes: 1 addition & 1 deletion templates/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ services:
environment:
profile: prod
db:
image: mongo:4.2.2
image: mongo:4.2.3
container_name: db
environment:
MONGO_INITDB_DATABASE: tech
Expand Down
5 changes: 1 addition & 4 deletions templates/server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,4 @@ module project-name

go 1.13

require (
github.com/gorilla/mux v1.7.3
go.mongodb.org/mongo-driver v1.2.1
)
require go.mongodb.org/mongo-driver v1.3.0
22 changes: 12 additions & 10 deletions templates/server/web/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,34 +2,36 @@ package web

import (
"encoding/json"
"github.com/gorilla/mux"
"log"
"net/http"
"project-name/db"
)

type App struct {
d db.DB
r *mux.Router
d db.DB
handlers map[string]http.HandlerFunc
}

func NewApp(d db.DB, cors bool) App {
app := App{
d: d,
r: mux.NewRouter(),
d: d,
handlers: make(map[string]http.HandlerFunc),
}
handler := app.GetTechnologies
techHandler := app.GetTechnologies
if !cors {
handler = disableCors(handler)
techHandler = disableCors(techHandler)
}
app.r.HandleFunc("/api/technologies", handler).Methods("GET")
app.r.PathPrefix("/").Handler(http.FileServer(http.Dir("/webapp")))
app.handlers["/api/technologies"] = techHandler
app.handlers["/"] = http.FileServer(http.Dir("/webapp")).ServeHTTP
return app
}

func (a *App) Serve() error {
for path, handler := range a.handlers {
http.Handle(path, handler)
}
log.Println("Web server is available on port 8080")
return http.ListenAndServe(":8080", a.r)
return http.ListenAndServe(":8080", nil)
}

func (a *App) GetTechnologies(w http.ResponseWriter, r *http.Request) {
Expand Down

0 comments on commit 2f0fc1a

Please sign in to comment.