golang 小web

golang 小web

package main

import (
    "fmt"
    "io/ioutil"
    "log"
    "net/http"
)

func Upload(w http.ResponseWriter, r *http.Request) {
    fmt.Println(r.RequestURI)

    file, _, err := r.FormFile("userfile")
    if err != nil {
        http.Error(w, err.Error(), 500)
        return
    }

    content, err := ioutil.ReadAll(file)
    if err != nil {
        err.Error()
        fmt.Fprintf(w, "%s.  %s!", err.Error(), r.Method)
    } else {
        fmt.Fprintf(w, "Thanks for the %s! \n", r.Method)
        fmt.Fprintf(w, "%s ", content)
    }

    //查询需要保存的节点

    //发送文件存储

    //文件存储返回的查询唯一值(唯一值包含信息??)

    //返回保存结果

}

func main() {
    fmt.Println("Proxy  REST API start...")
    http.HandleFunc("/", Upload)

    err := http.ListenAndServe(":9090", nil)
    if err != nil {
        log.Fatal(http.ListenAndServe, err)
    }
}

你可能感兴趣的:(golang)