Created
March 20, 2017 23:07
-
-
Save perigee/4f479499a59d3563b51cfa007e59d2b1 to your computer and use it in GitHub Desktop.
Simple Go restful server
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"encoding/json" | |
"log" | |
"net/http" | |
"flag" | |
"github.com/golang/glog" | |
"github.com/gorilla/mux" | |
) | |
type Sample struct { | |
Output string `json:"output"` | |
} | |
func CreateResult(w http.ResponseWriter, req *http.Request) { | |
var s Sample | |
_ = json.NewDecoder(req.Body).Decode(&s) | |
glog.Infof("receive: %v", s.Output) | |
} | |
func main() { | |
flag.Parse() | |
//logger := log.New(os.Stdout, "terraform: ", log.Lshortfile|log.LstdFlags) | |
router := mux.NewRouter() | |
router.HandleFunc("/result", CreateResult).Methods("PUT") | |
log.Fatal(http.ListenAndServe(":8089", router)) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Put json to endpoints
curl -H "Content-Type:application/json" -X PUT -d @tmp.json http://localhost:8089/result