2016年9月30日 星期五

Linux 程式減肥

使用指令
1.objcopy
objcopy -S -g apps

2.strip
strip apps

GO Web cgi server

package main

import(
  "net/http/cgi"
  "log"
  "net/http"
)

func main() {
  http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request){
    handler := new(cgi.Handler)
    handler.Path = "/root/goweb/" + r.URL.Path
//    handler.Dir = "/root/goweb/"

    log.Println(handler.Path)
    log.Println(handler.Args)

    handler.ServeHTTP(w, r)
  })

  log.Fatal(http.ListenAndServe(":8080",nil))
}

GO Web cgi server (直接執行 go )

package main

import(
  "net/http/cgi"
  "log"
  "net/http"
)

func main() {
  http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request){
    handler := new(cgi.Handler)
    handler.Path = "/usr/local/bin/go"
    script := "/root/goweb/" + r.URL.Path
    log.Println(handler.Path)
    handler.Dir = "/root/goweb/"
    args := []string{"run", script}
    handler.Args = append(handler.Args, args...)
    handler.Env = append(handler.Env, "GOPATH=/root/goweb")
    handler.Env = append(handler.Env, "GOROOT=/usr/local/go")
    log.Println(handler.Args)

    handler.ServeHTTP(w, r)
  })

  log.Fatal(http.ListenAndServe(":8080",nil))
}

GOLANG CGI範例

package main

import (
    "net/http/cgi"
    "net/http"
    "fmt"
)

func errorResponse(code int, msg string) {
    fmt.Printf("Status:%d %s\r\n", code, msg)
    fmt.Printf("Content-Type: text/plain\r\n")
    fmt.Printf("\r\n")
    fmt.Printf("%s\r\n", msg)
}

func main() {
    var req *http.Request
    var err error
    req, err = cgi.Request()
    if err != nil {
        errorResponse(500, "cannot get cgi request" + err.Error())
        return
    }

    fmt.Printf("Content-Type: text/html\r\n")
    fmt.Printf("\r\n")
    fmt.Printf("<pre>\n")
    fmt.Printf("req=%v\r\n", req)
}

2016年9月29日 星期四

Linux 取得網路流量

cat /proc/net/dev

ip -s link

2016年9月20日 星期二

GIT :error: src refspec master does not match any

錯誤的原因:目錄中沒有文件,空目錄是不能提交上去

 新增文件就可以
touch README
git add README
git commit -m 'first commit'
git push origin master

2016年9月19日 星期一

IPMI 取得伺服器電源使用狀態

FreeIPMI
ipmi-dcmi --get-system-power-statistics