本文整理匯總了Golang中hyper/engine.Env類的典型用法代碼示例。如果您正苦於以下問題:Golang Env類的具體用法?Golang Env怎麽用?Golang Env使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
在下文中一共展示了Env類的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: postContainerCreate
func postContainerCreate(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
if err := r.ParseForm(); err != nil {
return nil
}
glog.V(1).Infof("Image name is %s\n", r.Form.Get("imageName"))
job := eng.Job("create", r.Form.Get("imageName"))
stdoutBuf := bytes.NewBuffer(nil)
stderrBuf := bytes.NewBuffer(nil)
job.Stdout.Add(stdoutBuf)
job.Stderr.Add(stderrBuf)
if err := job.Run(); err != nil {
return err
}
var (
env engine.Env
dat map[string]interface{}
returnedJSONstr string
)
returnedJSONstr = engine.Tail(stdoutBuf, 1)
if err := json.Unmarshal([]byte(returnedJSONstr), &dat); err != nil {
return err
}
env.Set("ContainerID", dat["ContainerID"].(string))
return writeJSONEnv(w, http.StatusCreated, env)
}
示例2: getPodInfo
func getPodInfo(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
if err := r.ParseForm(); err != nil {
return nil
}
job := eng.Job("podInfo", r.Form.Get("podName"))
stdoutBuf := bytes.NewBuffer(nil)
job.Stdout.Add(stdoutBuf)
if err := job.Run(); err != nil {
return err
}
var (
env engine.Env
dat map[string]interface{}
returnedJSONstr string
)
returnedJSONstr = engine.Tail(stdoutBuf, 1)
if err := json.Unmarshal([]byte(returnedJSONstr), &dat); err != nil {
return err
}
env.Set("hostname", dat["hostname"].(string))
return writeJSONEnv(w, http.StatusCreated, env)
}
示例3: postPodRemove
func postPodRemove(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
if err := r.ParseForm(); err != nil {
return nil
}
glog.V(1).Infof("Pod(%s) is process to be removed", r.Form.Get("podId"))
job := eng.Job("podRm", r.Form.Get("podId"))
stdoutBuf := bytes.NewBuffer(nil)
job.Stdout.Add(stdoutBuf)
if err := job.Run(); err != nil {
return err
}
var (
env engine.Env
dat map[string]interface{}
returnedJSONstr string
)
returnedJSONstr = engine.Tail(stdoutBuf, 1)
if err := json.Unmarshal([]byte(returnedJSONstr), &dat); err != nil {
return err
}
env.Set("ID", dat["ID"].(string))
env.SetInt("Code", (int)(dat["Code"].(float64)))
env.Set("Cause", dat["Cause"].(string))
return writeJSONEnv(w, http.StatusOK, env)
}
示例4: postVmCreate
func postVmCreate(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
if err := r.ParseForm(); err != nil {
return nil
}
job := eng.Job("vmCreate", r.Form.Get("cpu"), r.Form.Get("mem"))
stdoutBuf := bytes.NewBuffer(nil)
job.Stdout.Add(stdoutBuf)
if err := job.Run(); err != nil {
return err
}
var (
env engine.Env
dat map[string]interface{}
returnedJSONstr string
)
returnedJSONstr = engine.Tail(stdoutBuf, 1)
if err := json.Unmarshal([]byte(returnedJSONstr), &dat); err != nil {
return err
}
env.Set("ID", dat["ID"].(string))
env.SetInt("Code", (int)(dat["Code"].(float64)))
env.Set("Cause", dat["Cause"].(string))
return writeJSONEnv(w, http.StatusOK, env)
}
示例5: getList
func getList(eng *engine.Engine, version version.Version, w http.ResponseWriter, r *http.Request, vars map[string]string) error {
if err := r.ParseForm(); err != nil {
return nil
}
glog.V(1).Infof("List type is %s\n", r.Form.Get("item"))
job := eng.Job("list", r.Form.Get("item"))
stdoutBuf := bytes.NewBuffer(nil)
job.Stdout.Add(stdoutBuf)
if err := job.Run(); err != nil {
return err
}
str := engine.Tail(stdoutBuf, 1)
type listResponse struct {
Item string `json:"item"`
PodData []string `json:"podData"`
VmData []string `json:"vmData"`
CData []string `json:"cData"`
}
var res listResponse
if err := json.Unmarshal([]byte(str), &res); err != nil {
return err
}
var env engine.Env
env.Set("Item", res.Item)
if res.Item == "pod" {
env.SetList("podData", res.PodData)
}
if res.Item == "vm" {
env.SetList("vmData", res.VmData)
}
if res.Item == "container" {
env.SetList("cData", res.CData)
}
return writeJSONEnv(w, http.StatusOK, env)
}
示例6: writeJSONEnv
// writeJSONEnv writes the engine.Env values to the http response stream as a
// json encoded body.
func writeJSONEnv(w http.ResponseWriter, code int, v engine.Env) error {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(code)
return v.Encode(w)
}