Simple blank "Hello, World!" setup combining Gin (golang) + React + Webpack. Create files with these codes, download dependencies and run.
app/src/index.jsx
Source code viewer
import React from 'react'; import ReactDOM from 'react-dom'; ReactDOM.render( <div>browse-tutorials.com</div>, document.getElementById('app') );Programming Language: ECMAScript
app/.babelrc
Source code viewer
{ "presets": ["@babel/preset-env", "@babel/preset-react"] }Programming Language: Javascript
app/package.json
Source code viewer
{ "name": "app", "scripts": { "watch": "node_modules/webpack/bin/webpack.js --mode development --watch", "build": "node_modules/webpack/bin/webpack.js --mode production" }, "dependencies": { "react": "^16.13.1", "react-dom": "^16.13.1" }, "devDependencies": { "@babel/core": "^7.9.0", "@babel/preset-env": "^7.9.0", "@babel/preset-react": "^7.9.4", "babel-loader": "^8.1.0", "webpack": "^4.42.1", "webpack-cli": "^3.3.11" } } Programming Language: Javascript
app/webpack.config.js
Source code viewer
const path = require('path'); module.exports = { module: { rules: [ { test: /\.jsx?$/, exclude: /node_modules/, use: ['babel-loader'] } ] }, resolve: { extensions: ['.js', '.jsx'] }, output: { path: path.resolve(__dirname, '../static'), publicPath: '/', filename: 'bundle.js' }, entry: { bundle: './src/index.jsx' } };Programming Language: ECMAScript
main.go
Source code viewer
package main import ( "net/http" "github.com/gin-gonic/contrib/static" "github.com/gin-gonic/gin" ) func main() { // Init router router := gin.Default() // Serve frontend static files router.Use(static.Serve("/", static.LocalFile("./static", true))) // Setup route group for the API api := router.Group("/api") { api.GET("/", func(c *gin.Context) { c.JSON(http.StatusOK, gin.H{ "message": "pong", }) }) } // Start and run the server router.Run(":3000") }Programming Language: Go
Run npm install and build from app directory. Use "go run main.go" to compile backend and start the webserver. This is a simple "Hello, World!" setup. A good starting point.