當前位置: 首頁>>代碼示例>>Golang>>正文


Golang models.Provider函數代碼示例

本文整理匯總了Golang中github.com/convox/rack/api/models.Provider函數的典型用法代碼示例。如果您正苦於以下問題:Golang Provider函數的具體用法?Golang Provider怎麽用?Golang Provider使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。


在下文中一共展示了Provider函數的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。

示例1: BuildGet

func BuildGet(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	vars := mux.Vars(r)
	app := vars["app"]
	build := vars["build"]

	b, err := models.Provider().BuildGet(app, build)
	if awsError(err) == "ValidationError" {
		return httperr.Errorf(404, "no such app: %s", app)
	}
	if err != nil && strings.HasPrefix(err.Error(), "no such build") {
		return httperr.Errorf(404, err.Error())
	}
	if err != nil {
		return httperr.Server(err)
	}

	l, err := models.Provider().BuildLogs(app, build)
	if err != nil {
		return httperr.Server(err)
	}

	b.Logs = l

	return RenderJson(rw, b)
}
開發者ID:gmelika,項目名稱:rack,代碼行數:25,代碼來源:builds.go

示例2: BuildDelete

// BuildDelete deletes a build. Makes sure not to delete a build that is contained in the active release
func BuildDelete(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	vars := mux.Vars(r)
	appName := vars["app"]
	buildID := vars["build"]

	active, err := isBuildActive(appName, buildID)
	if err != nil {
		return httperr.Errorf(404, err.Error())
	}
	if active {
		return httperr.Errorf(400, "cannot delete build contained in active release")
	}

	err = models.Provider().ReleaseDelete(appName, buildID)
	if err != nil {
		return httperr.Server(err)
	}

	build, err := models.Provider().BuildDelete(appName, buildID)
	if err != nil {
		return httperr.Server(err)
	}

	return RenderJson(rw, build)
}
開發者ID:gmelika,項目名稱:rack,代碼行數:26,代碼來源:builds.go

示例3: ForkRelease

// ForkRelease creates a new release based on the app's release
func ForkRelease(app *structs.App) (*structs.Release, error) {
	release := structs.NewRelease(app.Name)

	if app.Release != "" {
		r, err := models.Provider().ReleaseGet(app.Name, app.Release)
		if err != nil {
			return nil, err
		}
		id := release.Id
		created := release.Created

		release = r
		release.Id = id
		release.Created = created
	}

	env, err := models.Provider().EnvironmentGet(app.Name)
	if err != nil {
		fmt.Printf("fn=ForkRelease level=error msg=\"error getting environment: %s\"", err)
	}

	release.Env = env.Raw()

	return &structs.Release{
		Id:       release.Id,
		App:      release.App,
		Build:    release.Build,
		Env:      release.Env,
		Manifest: release.Manifest,
		Created:  release.Created,
	}, nil
}
開發者ID:convox,項目名稱:rack,代碼行數:33,代碼來源:releases.go

示例4: BuildCreate

func BuildCreate(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	vars := mux.Vars(r)
	app := vars["app"]

	cache := !(r.FormValue("cache") == "false")
	manifest := r.FormValue("manifest")
	description := r.FormValue("description")

	repo := r.FormValue("repo")
	index := r.FormValue("index")

	source, _, err := r.FormFile("source")
	if err != nil && err != http.ErrMissingFile && err != http.ErrNotMultipart {
		helpers.TrackError("build", err, map[string]interface{}{"at": "FormFile"})
		return httperr.Server(err)
	}

	// Log into private registries that we might pull from
	// TODO: move to prodiver BuildCreate
	err = models.LoginPrivateRegistries()
	if err != nil {
		return httperr.Server(err)
	}

	a, err := models.GetApp(app)
	if err != nil {
		return httperr.Server(err)
	}

	// Log into registry that we will push to
	_, err = models.AppDockerLogin(*a)
	if err != nil {
		return httperr.Server(err)
	}

	var b *structs.Build

	// if source file was posted, build from tar
	if source != nil {
		b, err = models.Provider().BuildCreateTar(app, source, r.FormValue("manifest"), r.FormValue("description"), cache)
	} else if repo != "" {
		b, err = models.Provider().BuildCreateRepo(app, repo, r.FormValue("manifest"), r.FormValue("description"), cache)
	} else if index != "" {
		var i structs.Index
		err := json.Unmarshal([]byte(index), &i)
		if err != nil {
			return httperr.Server(err)
		}

		b, err = models.Provider().BuildCreateIndex(app, i, manifest, description, cache)
	} else {
		return httperr.Errorf(403, "no source, repo or index")
	}

	if err != nil {
		return httperr.Server(err)
	}

	return RenderJson(rw, b)
}
開發者ID:gmelika,項目名稱:rack,代碼行數:60,代碼來源:builds.go

示例5: BuildList

func BuildList(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	app := mux.Vars(r)["app"]

	l := r.URL.Query().Get("limit")

	var err error
	var limit int

	if l == "" {
		limit = 20
	} else {
		limit, err = strconv.Atoi(l)
		if err != nil {
			return httperr.Errorf(400, err.Error())
		}
	}

	builds, err := models.Provider().BuildList(app, int64(limit))
	if awsError(err) == "ValidationError" {
		return httperr.Errorf(404, "no such app: %s", app)
	}
	if err != nil {
		return httperr.Server(err)
	}

	return RenderJson(rw, builds)
}
開發者ID:gmelika,項目名稱:rack,代碼行數:27,代碼來源:builds.go

示例6: AppLogs

func AppLogs(ws *websocket.Conn) *httperr.Error {
	app := mux.Vars(ws.Request())["app"]
	header := ws.Request().Header

	var err error

	follow := true
	if header.Get("Follow") == "false" {
		follow = false
	}

	since := 2 * time.Minute
	if s := header.Get("Since"); s != "" {
		since, err = time.ParseDuration(s)
		if err != nil {
			return httperr.Errorf(403, "Invalid duration %s", s)
		}
	}

	err = models.Provider().LogStream(app, ws, structs.LogStreamOptions{
		Filter: header.Get("Filter"),
		Follow: follow,
		Since:  time.Now().Add(-1 * since),
	})
	if err != nil {
		if strings.HasSuffix(err.Error(), "write: broken pipe") {
			return nil
		}
		return httperr.Server(err)
	}
	return nil
}
開發者ID:gmelika,項目名稱:rack,代碼行數:32,代碼來源:apps.go

示例7: SystemLogs

// SystemLogs returns the logs for the Rack
func SystemLogs(ws *websocket.Conn) *httperr.Error {
	header := ws.Request().Header

	var err error

	follow := true
	if header.Get("Follow") == "false" {
		follow = false
	}

	since := 2 * time.Minute
	if s := header.Get("Since"); s != "" {
		since, err = time.ParseDuration(s)
		if err != nil {
			return httperr.Errorf(403, "Invalid duration %s", s)
		}
	}

	err = models.Provider().SystemLogs(ws, structs.LogStreamOptions{
		Filter: header.Get("Filter"),
		Follow: follow,
		Since:  time.Now().Add(-1 * since),
	})
	if err != nil {
		return httperr.Server(err)
	}

	return nil
}
開發者ID:gmelika,項目名稱:rack,代碼行數:30,代碼來源:system.go

示例8: ProcessRunAttached

func ProcessRunAttached(ws *websocket.Conn) *httperr.Error {
	vars := mux.Vars(ws.Request())
	header := ws.Request().Header

	app := vars["app"]
	process := vars["process"]
	command := header.Get("Command")
	release := header.Get("Release")
	height, _ := strconv.Atoi(header.Get("Height"))
	width, _ := strconv.Atoi(header.Get("Width"))

	_, err := models.Provider().ProcessRun(app, process, structs.ProcessRunOptions{
		Command: command,
		Height:  height,
		Width:   width,
		Release: release,
		Stream:  ws,
	})
	if provider.ErrorNotFound(err) {
		return httperr.New(404, err)
	}
	if err != nil {
		return httperr.Server(err)
	}

	return nil
}
開發者ID:convox,項目名稱:rack,代碼行數:27,代碼來源:processes.go

示例9: BuildDelete

// BuildDelete deletes a build. Makes sure not to delete a build that is contained in the active release
func BuildDelete(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	vars := mux.Vars(r)
	appName := vars["app"]
	buildID := vars["build"]

	err := models.Provider().ReleaseDelete(appName, buildID)
	if err != nil {
		return httperr.Server(err)
	}

	build, err := models.Provider().BuildDelete(appName, buildID)
	if err != nil {
		return httperr.Server(err)
	}

	return RenderJson(rw, build)
}
開發者ID:convox,項目名稱:rack,代碼行數:18,代碼來源:builds.go

示例10: SystemCapacity

func SystemCapacity(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	capacity, err := models.Provider().CapacityGet()
	if err != nil {
		return httperr.Server(err)
	}

	return RenderJson(rw, capacity)
}
開發者ID:gmelika,項目名稱:rack,代碼行數:8,代碼來源:system.go

示例11: RegistryList

func RegistryList(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	registries, err := models.Provider().RegistryList()
	if err != nil {
		return httperr.Server(err)
	}

	return RenderJson(rw, registries)
}
開發者ID:convox,項目名稱:rack,代碼行數:8,代碼來源:registries.go

示例12: SystemShow

func SystemShow(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	rack, err := models.Provider().SystemGet()
	if err != nil {
		return httperr.Server(err)
	}

	return RenderJson(rw, rack)
}
開發者ID:gmelika,項目名稱:rack,代碼行數:8,代碼來源:system.go

示例13: SystemReleases

// SystemReleases lists the latest releases of the rack
func SystemReleases(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	releases, err := models.Provider().SystemReleases()
	if err != nil {
		return httperr.Server(err)
	}

	return RenderJson(rw, releases)
}
開發者ID:gmelika,項目名稱:rack,代碼行數:9,代碼來源:system.go

示例14: InstancesList

func InstancesList(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	instances, err := models.Provider().InstanceList()
	if err != nil {
		return httperr.Server(err)
	}

	return RenderJson(rw, instances)
}
開發者ID:gmelika,項目名稱:rack,代碼行數:8,代碼來源:instances.go

示例15: InstanceTerminate

func InstanceTerminate(rw http.ResponseWriter, r *http.Request) *httperr.Error {
	id := mux.Vars(r)["id"]

	if err := models.Provider().InstanceTerminate(id); err != nil {
		return httperr.Server(err)
	}

	return RenderSuccess(rw)
}
開發者ID:convox,項目名稱:rack,代碼行數:9,代碼來源:instances.go


注:本文中的github.com/convox/rack/api/models.Provider函數示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。