Skip to content

Instantly share code, notes, and snippets.

@cn007b
Last active April 17, 2020 09:45
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 cn007b/c97f39f19a81aa87e0c176fe5bb63ebc to your computer and use it in GitHub Desktop.
Save cn007b/c97f39f19a81aa87e0c176fe5bb63ebc to your computer and use it in GitHub Desktop.
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