Skip to content

Instantly share code, notes, and snippets.

@ThomasJunk
Created June 25, 2021 11:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ThomasJunk/fbb34693d8d1ef3fc2bd95142d5e93c5 to your computer and use it in GitHub Desktop.
Save ThomasJunk/fbb34693d8d1ef3fc2bd95142d5e93c5 to your computer and use it in GitHub Desktop.
Template for personal go projects
#!/bin/bash
WORKDIR=${PWD##*/}
MAINDIR="cmd/$WORKDIR"
mkdir -p "$MAINDIR"
MAIN=$(cat <<-EOF
package main
import "fmt"
func main(){
fmt.Println("hello world!")
}
EOF
)
MAKEFILE=$(cat <<-EOF
# SPDX-License-Identifier: MIT
# © 2021 Thomas Junk
GOCMD=go
GOBUILD=\$(GOCMD) build
NAME=$WORKDIR
PATHTOMAIN=./cmd/\$(NAME)
all:\tbuild
build:
\t\$(GOBUILD) -o \$(NAME) \$(PATHTOMAIN)/main.go
EOF
)
RUNAPP=$(cat <<-EOF
#!/usr/bin/env bash
# SPDX-License-Identifier: MIT
# © 2021 Thomas Junk
exec 2>&1 ./$WORKDIR
EOF
)
echo -e "$MAKEFILE" > makefile
echo "$RUNAPP" > run-app.sh
chmod u+x run-app.sh
echo "$MAIN" > $MAINDIR/main.go
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment