/golang-nextjs-portable

Go program with embedded Next.js app.

Primary LanguageGoMIT LicenseMIT

golang-nextjs-portable

golang-nextjs-portable is a small Go program to showcase the embed package for bundling a static HTML export of a Next.js app.

👉 Read the companion article that walks through this project.

*** After I fork these project from David Stotijn.

*** I changed net/http to Fiber V2 and use GORM V2 connect the SQLite3 database for stress test.

Requirements

  • Go 1.16
  • Yarn

Installing

Clone or download the repository:

$ git clone git@github.com:dstotijn/golang-nextjs-portable.git

Usage

From the repository root directory, generate the static HTML export of the Next.js app, and build the Go binary:

$ cd nextjs
$ yarn install
$ yarn run export
$ cd ..
$ go build main.go

On Windows PowerShell

$ cd nextjs\
$ set-ExecutionPolicy RemoteSigned -Scope CurrentUser
$ Get-ExecutionPolicy
$ yarn install
$ yarn run export-win
$ cd ..
$ go build main.go

Run Go unit test

$ go test -v

Run Stress test on Windows 10

$ C:\xampp\apache\bin\ab.exe -k -p test.json -T application/json -c 10000 -n 70000 http://localhost:8080/add

Run Stress test with Hay

$ hey -m POST -D ./test.json -T "application/json" -c 10000 -n 50000 http://localhost:8080/add

Then run the binary:

$ ./golang-nextjs-portable

2021/04/27 14:55:38 Starting HTTP server at http://localhost:8080 ...

On Windows PowerShell

$ ./main.exe

2021/05/22 20:29:22 Starting HTTP server at http://localhost:8080 ...

On Docker

docker build .

License

MIT


© 2021 David Stotijn — Twitter, Email, Homepage