zoukankan      html  css  js  c++  java
  • 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))
    }
    

      

  • 相关阅读:
    View Controller 生命周期的各个方法的用法
    IOS开发之Post 方式获取服务器数据
    委托代理
    Function
    SKPhysicsContactDelegate协议
    UITouch附加
    Remove Duplicates from Sorted Array II
    4Sum
    [Text Justification
    Count and Say
  • 原文地址:https://www.cnblogs.com/webglcn/p/9197243.html
Copyright © 2011-2022 走看看