This project was inspired by olebedev's golang-starter-kit and improve some features which can bootstrap SPA web quickly and efficiently based on Facebook React and Gin Golang Server side framework.
- Routing via react-router
- ES6 & JSX via babel-loader with minimal runtime dependency footprint
- Redux as state container
- Redux-devtools
- Redux Saga for asynchronous requests
- Hot reloading via react-transform & HMR
- Css styles without global namespace via PostCSS, css-loader & css-modules
- Webpack bundle builder
- Eslint and golint rules for Makefile
- Server side render via goja
- Api requests between your react application and server side application directly via fetch polyfill
- Title, Open Graph and other domain-specific meta tags render for each page at the server and at the client
- Server side redirect
- Embedding static files into artefact via bindata
- Popular golang gin framework
- Advanced cli via cli
- Makefile based projectd
- Separated config files: development, staging, production via viper
Note that probably not works at windows.
$ tree server
server
├── config <-- Config file will be loaded via viper
│ └── config-development.json
│ └── config-staging.json
│ └── config-production.json
├── api.go
├── app.go
├── bindata.go <-- this file is gitignored, it will appear at compile time
├── data
│ └── templates
│ └── react.html
├── main.go <-- main function declared here
├── react.go
└── utils.go
The ./server/
is flat golang package.
It's simple React application
$ tree client
client
├── actions.js
├── components
│ ├── app
│ │ ├── favicon.ico
│ │ ├── index.js
│ │ └── styles.css
│ ├── homepage
│ │ ├── index.js
│ │ └── styles.css
│ ├── not-found
│ │ ├── index.js
│ │ └── styles.css
│ └── usage
│ ├── index.js
│ └── styles.css
├── css
│ ├── funcs.js
│ ├── global.css
│ ├── index.js
│ └── vars.js
├── index.js <-- main function declared here
├── reducers.js
├── sagas.js
├── router
│ ├── index.js
│ ├── routes.js
│ └── toString.js
└── store.js
The client app will be compiled into server/data/static/build/
. Then it will be embedded into go package via go-bindata. After that the package will be compiled into binary.
Convention: javascript app should declare main function right in the global namespace. It will used to render the app at the server side.
Clone the repo:
$ https://github.com/ntquan1704/gin-react-starter-kit.git $GOPATH/src/<project>
$ cd $GOPATH/src/<project>
Install dependencies:
$ make install
Start dev server:
$ make serve
that's it. Open http://localhost:5001/(if you use default port) at your browser. Now you ready to start coding your awesome project.
Install dependencies and type ENV=production make build
. This rule is producing webpack build and regular golang build after that. Result you can find at $GOPATH/bin
. Note that the binary will be named as the current project directory.
- cd $GOPATH/src/
- Run: ENV=production $GOPATH/bin/ run
MIT