本文整理汇总了Golang中github.com/cocaine/cocaine-flow/backend.Cocaine类的典型用法代码示例。如果您正苦于以下问题:Golang Cocaine类的具体用法?Golang Cocaine怎么用?Golang Cocaine使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Cocaine类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: ApplicationStart
func ApplicationStart(cocs backend.Cocaine, w http.ResponseWriter, r *http.Request) {
name := r.FormValue("name")
profile := r.FormValue("profile")
if len(name) == 0 || len(profile) == 0 {
http.Error(w, "name or profile wasn't specified", http.StatusInternalServerError)
return
}
stream, err := cocs.ApplicationStart(name, profile)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
if f, ok := w.(http.Flusher); !ok {
for {
var p []byte
_, err := stream.Read(p)
fmt.Println(p, err)
if err != nil {
break
}
w.Write(p)
f.Flush()
}
} else {
body, _ := ioutil.ReadAll(stream)
fmt.Fprintf(w, "%s", body)
}
}
示例2: ApplicationUpload
func ApplicationUpload(cocs backend.Cocaine, w http.ResponseWriter, r *http.Request) {
name := mux.Vars(r)["name"]
version := mux.Vars(r)["version"]
defer r.Body.Close()
path, err := archive.Unpack(r.Body)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
defer os.RemoveAll(path)
info := backend.AppUplodaInfo{
Path: path,
App: name,
Version: version,
}
ch, _, err := cocs.ApplicationUpload(info)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
for lg := range ch {
w.Write([]byte(lg))
w.(http.Flusher).Flush()
}
}
示例3: HostList
func HostList(cocs backend.Cocaine, w http.ResponseWriter, r *http.Request) {
hosts, err := cocs.HostList()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
SendJson(w, hosts)
}
示例4: ApplicationList
func ApplicationList(cocs backend.Cocaine, w http.ResponseWriter, r *http.Request) {
apps, err := cocs.ApplicationList()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
SendJson(w, apps)
}
示例5: BuildLogList
func BuildLogList(cocs backend.Cocaine, w http.ResponseWriter, r *http.Request) {
buildlogs, err := cocs.BuildLogList()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
SendJson(w, buildlogs)
}
示例6: GroupRemove
func GroupRemove(cocs backend.Cocaine, w http.ResponseWriter, r *http.Request) {
name := mux.Vars(r)["name"]
err := cocs.GroupRemove(name)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
fmt.Fprint(w, "OK")
}
示例7: GroupRead
func GroupRead(cocs backend.Cocaine, w http.ResponseWriter, r *http.Request) {
name := mux.Vars(r)["name"]
group, err := cocs.GroupRead(name)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
SendJson(w, group)
}
示例8: HostAdd
func HostAdd(cocs backend.Cocaine, w http.ResponseWriter, r *http.Request) {
host := mux.Vars(r)["host"]
err := cocs.HostAdd(host)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
fmt.Fprint(w, "OK")
}
示例9: CrashlogList
func CrashlogList(cocs backend.Cocaine, w http.ResponseWriter, r *http.Request) {
name := mux.Vars(r)["name"]
crashlogs, err := cocs.CrashlogList(name)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
SendJson(w, crashlogs)
}
示例10: ProfileList
func ProfileList(cocs backend.Cocaine, w http.ResponseWriter, r *http.Request) {
profiles, err := cocs.ProfileList()
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
SendJson(w, profiles)
}
示例11: BuildLogRead
func BuildLogRead(cocs backend.Cocaine, w http.ResponseWriter, r *http.Request) {
id := mux.Vars(r)["id"]
buildlog, err := cocs.BuildLogRead(id)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
fmt.Fprintf(w, buildlog)
}
示例12: GroupPopApp
func GroupPopApp(cocs backend.Cocaine, w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
name := vars["name"]
app := vars["app"]
err := cocs.GroupPopApp(name, app)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
fmt.Fprint(w, "OK")
}
示例13: ProfileUpload
func ProfileUpload(cocs backend.Cocaine, w http.ResponseWriter, r *http.Request) {
name := mux.Vars(r)["name"]
defer r.Body.Close()
body, _ := ioutil.ReadAll(r.Body)
if len(body) == 0 {
http.Error(w, "Empty profile", http.StatusInternalServerError)
return
}
err := cocs.ProfileUpload(name, body)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
fmt.Fprintln(w, "OK")
}
示例14: CrashlogView
func CrashlogView(cocs backend.Cocaine, w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
name := vars["name"]
timestamp, err := strconv.Atoi(vars["timestamp"])
if err != nil {
http.Error(w, "timestamp must be a number", http.StatusBadRequest)
return
}
crashlog, err := cocs.CrashlogView(name, timestamp)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
fmt.Fprintf(w, crashlog)
}
示例15: GroupPushApp
func GroupPushApp(cocs backend.Cocaine, w http.ResponseWriter, r *http.Request) {
vars := mux.Vars(r)
name := vars["name"]
app := vars["app"]
weights, ok := r.URL.Query()["weight"]
if !ok || len(weights) == 0 {
http.Error(w, "weight argument is absent", http.StatusBadRequest)
return
}
weight, err := strconv.Atoi(weights[0])
if err != nil {
http.Error(w, "weight must be an integer value", http.StatusBadRequest)
return
}
err = cocs.GroupPushApp(name, app, weight)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
fmt.Fprint(w, "OK")
}