go chapter 1

 case 1

// helloworld.go
package main

import "fmt"

func main() {
    fmt.Println("Hello,	世界") 
}
go run helloworld.go

go build helloworldgo
./helloworld

 

case 2

package  main

import (
  "fmt"
  "os"
)

func main() {
  var s, sep string
  for i := 1; i < len(os.Args); i++ {
    s += sep + os.Args[i]
    sep = " "
  }
  fmt.Println(s)
}

case 3 package main

import (
  "fmt"
  "os"
)

func main() {
  var s, sep string
  for i, arg := range os.Args[1] {
    fmt.Println(i, arg)
    s += sep + arg
    sep = " "
  }
  fmt.Println(s)
}

  

case 4 - http

package main

import (
    "fmt"
    "net/http"
)

func IndexHandler(w http.ResponseWriter, r *http.Request) {
    fmt.Fprintln(w, "hello world")
}
 
func main() {
    http.HandleFunc("/", IndexHandler)
    http.ListenAndServe("127.0.0.1:8000", nil)
}

case 5 - http prometheus

package main

import (
    "log"
    "net/http"
    "github.com/prometheus/client_golang/prometheus/promhttp"
)
func main() {
    http.Handle("/metrics", promhttp.Handler())
    log.Fatal(http.ListenAndServe(":8080", nil))
}

  

原文地址:https://www.cnblogs.com/webglcn/p/9197243.html