Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Super simple GO examples

Super simple GO examples

Super simple golang code examples:

cli.go:

package main

import (
	"fmt"
)

func main() {
	cli()
}

func cli() {
	name, ending := "World", "!"
	ending2 := `)`
	fmt.Printf("Hello %s %s%s \n", name, ending, ending2)
}

web.go:

package main

import (
	"net/http"
)

func main() {
	web()
}

func web() {
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		msg := "Hello world!"
		w.Write([]byte(msg))
	})
	http.ListenAndServe(":8080", nil)
}

PS

You can find more stuff like this in my demo repo.
Source code, examples, explanation info, etc. just go and check it out!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment