Gonic is a high-performance, lightweight and scalable HTTP framework for Go Language. It is widely used for building APIs, microservices and web applications.
In this tutorial, we will be showing how to install Gonic on NixOS latest version. The steps involve configuring Nix shell, cloning Gonic repository from github and building the source code.
Before beginning with the installation, we assume that you have already installed:
We will first configure the Nix environment by creating a new project directory and entering it.
$ mkdir gonic-demo
$ cd gonic-demo/
Next, we'll create a default.nix
file in the project directory with the following contents to setup Nix shell environment.
{ pkgs ? import <nixpkgs> {}
, goVersion ? "1.16"
}:
pkgs.mkShell {
name = "gonic-env";
buildInputs = with pkgs; [
go
git
mercurial
];
shellHook = ''
export GOPATH=$PWD/go
export GOBIN=$GOPATH/bin
export PATH=$PATH:$GOBIN
'';
env = [
"GOROOT=${pkgs.go}/go"
"GOVERSION=${goVersion}"
];
}
The above configuration script will install and configure the necessary dependencies for building Gonic.
Once the file is in place, we will create a new Nix shell for it.
$ nix-shell
This will create a new shell, which will take us directly to the project directory.
We will now clone the Gonic repository from github.
$ git clone https://github.com/sentriz/gonic.git
This will create a new gonic directory in our project directory.
We will now build Gonic by entering into gonic directory and building the source code.
$ cd gonic/
$ go build -o gonic
Once the build process is complete, we can check if the binary was generated successfully.
$ ./gonic --version
This should output the versions of Gonic and Go installed.
In this tutorial, we have learned how to install Gonic on NixOS latest version by configuring the Nix environment with necessary dependencies, cloning Gonic repository from github and building the source code.
We hope this tutorial has been helpful for you in setting up Gonic on your machine.
If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!