Skip to content

Commit

Permalink
「🎉」init: an api written in go!
Browse files Browse the repository at this point in the history
  • Loading branch information
sh-koh committed Aug 4, 2024
0 parents commit 8aa79b8
Show file tree
Hide file tree
Showing 9 changed files with 851 additions and 0 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
29 changes: 29 additions & 0 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Test building

on:
workflow_dispatch:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.22.5'

- name: Build
run: go build -v ./...

- name: Install Nix
uses: cachix/install-nix-action@v25
with:
nix_path: nixpkgs=channel:nixos-unstable

- run: nix build .# --show-trace
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.direnv
result
674 changes: 674 additions & 0 deletions LICENSE

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# 🤖 Gap - WIP

Gap is a modular REST API with which you can interact to view, add and remove content.
It's a project for practicing my Go skills so there's nothing really fancy, just me learning...

## 📑 Features

You can launch it from the command line and add some arguments.
```bash
$ gap -h
Usage: gap [-p PORT | -h]
$ gap -p 8080
Server is running at 'http://localhost:8080'
```

## 🔨 Building

#### 🐁 Go
```bash
$ go build .
```

#### ❄️ Nix
```bash
$ nix build .#
```
58 changes: 58 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
description = "A development environment for this go project";

inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
flake-parts.url = "github:hercules-ci/flake-parts";
};

outputs = inputs:
inputs.flake-parts.lib.mkFlake { inherit inputs; } {
systems = [ "x86_64-linux" "aarch64-linux" ];
perSystem = { pkgs, ... }: {
devShells.default = pkgs.mkShell {
packages = with pkgs; [ go air delve ];
};
packages.default = pkgs.buildGoModule {
name = "gap";
src = ./.;
version = "git";
vendorHash = null;
};
};
};
}
3 changes: 3 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module github.com/sh-koh/gap

go 1.22.5
34 changes: 34 additions & 0 deletions main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package main

import (
"fmt"
"net/http"
"os"
"strconv"
)

func main() {
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("Welcome to the main page!"))
})
http.HandleFunc("/test", func(w http.ResponseWriter, r *http.Request) {
w.Write([]byte("This page is for testing."))
})

for i, arg := range os.Args {
if i != 0 {
switch arg {
case "-p":
if len(os.Args) > i+1 {
p, _ := strconv.Atoi(os.Args[i+1])
fmt.Printf("Server is running at 'http://localhost:%d'\n", p)
http.ListenAndServe(fmt.Sprintf(":%d", p), nil)
} else {
fmt.Println("You need to provide an argument to '-d'")
}
case "-h":
fmt.Printf("Usage: %s [-p PORT | -h]\n", os.Args[0])
}
}
}
}

0 comments on commit 8aa79b8

Please sign in to comment.