Learn Go in ~5mins
This is inspired by A half-hour to learn Rust and Zig in 30 minutes.
Basics
Your first Go program as a classical "Hello World" is pretty simple:
First we create a workspace for our project:
--- | |
version: "3.8" | |
services: | |
hello: | |
image: prologic/hello-go | |
networks: | |
- traefik | |
deploy: | |
mode: replicated |
module twtxt-search-engine | |
go 1.14 | |
require ( | |
github.com/gocolly/colly/v2 v2.1.0 | |
github.com/jointwt/twtxt v0.0.0-20210108082814-7098fcfa49df | |
github.com/prologic/read-file-last-line v0.0.0-20200806014221-326f63458987 | |
github.com/sirupsen/logrus v1.7.0 | |
) |
--- | |
version: "3.8" | |
services: | |
traefik: | |
image: traefik:latest | |
ports: | |
- target: 80 | |
published: 80 | |
protocol: tcp |
--- | |
version: "3.8" | |
services: | |
hello: | |
image: r.mills.io/prologic/hello-go | |
networks: | |
- traefik | |
deploy: | |
mode: replicated |
This is inspired by A half-hour to learn Rust and Zig in 30 minutes.
Your first Go program as a classical "Hello World" is pretty simple:
First we create a workspace for our project:
package main | |
import ( | |
"bytes" | |
"crypto/hmac" | |
"crypto/md5" | |
"encoding/hex" | |
"fmt" | |
"hash" | |
"net" |
<figure> | |
<a href="pics/earth2150/lc-combat-ucs.jpg"> | |
<img src="pics/earth2150/lc-combat-ucs.jpg" /> | |
</a> | |
<figcaption> | |
<abbr title="Lunar Corporation">LC</abbr>hovertanks battle mechs guarding a | |
<abbr title="United Civilized States">UCS</abbr>base. A large mech is shooting rockets at a hovertank, while its shields protect it from an electro cannon attack. Two repairers fix a visibly damaged nuclear power plant.</figcaption> | |
</figure> |
# ./congine /bin/sh | |
# hostname | |
container | |
# id | |
uid=0(root) gid=0(root) groups=0(root),0(root),65534,65534,65534,65534,65534,65534 | |
# ps aux | |
PID USER TIME COMMAND | |
1 root 0:00 /bin/sh | |
4 root 0:00 ps aux | |
# Container Terminated |
Loading /etc/os-release ... | |
You should have EPEL enabled to install all the prerequisites. | |
Check: http://www.tecmint.com/how-to-enable-epel-repository-for-rhel-centos-6-5/ | |
Running in non-interactive mode | |
> CentOS Version: 8 ... | |
> Checking for epel ... | |
Running in non-interactive mode, assuming yes (y) | |
> Would have promptedfor epel not found, shall I install it? ... | |
yum -y install epel-release | |
CentOS-8 - AppStream [=== ] --- B/s | 0 B --:-- ETA CentOS-8 - AppStream100% [====================] 1.4 kB/s | 681 B 00:00 ETA CentOS-8 - AppStream 17% [===- ] 242 kB/s | 1.2 MB 00:22 ETA CentOS-8 - AppStream 35% [======= ] 461 kB/s | 2.3 MB 00:09 ETA CentOS-8 - AppStream 45% [========= ] 565 kB/s | 3.0 MB 00:06 ETA CentOS-8 - AppStream 56% [=========== ] 687 kB/s | 3.7 MB 00:04 ETA CentOS-8 - AppStream 70% [============== ] 825 kB/s | 4.6 MB 00:02 ETA CentOS-8 - AppStream 85% [================= ] 979 kB/s | 5.6 MB |