openapi

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 11, 2024 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

View Source
const (
	// ApplicationJSONCharsetUTF8  应用类型:application/json;charset=UTF-8
	ApplicationJSONCharsetUTF8 = "application/json;charset=UTF-8"

	// DefaultEnv 默认环境
	DefaultEnv = "DEV"
	// DefaultCluster 默认集群
	DefaultCluster = "default"
)

Variables

View Source
var (
	// ErrStatusBadRequest 400 - Bad Request
	ErrStatusBadRequest = stderrors.New("400 - Bad Request - 客户端传入参数的错误,如操作人不存在,Namespace 不存在等等,客户端需要根据提示信息检查对应的参数是否正确。")
	// ErrStatusUnauthorized 401 - Bad Request
	ErrStatusUnauthorized = stderrors.New("401 - Bad Request - 接口传入的 Token 非法或者已过期,客户端需要检查 Token 是否传入正确。")
	// ErrStatusForbidden 403 - Forbidden
	ErrStatusForbidden = stderrors.New("403 - Forbidden - 接口要访问的资源未得到授权,比如只授权了对 A 应用下 Namespace 的管理权限,但是却尝试管理 B 应用下的配置。")
	// ErrStatusNotFound 404 - Not Found
	ErrStatusNotFound = stderrors.New("404 - Not Found - 接口要访问的资源不存在,一般是 URL 或 URL 的参数错误。")
	// ErrStatusMethodNotAllowed 405 - Method Not Allowed
	ErrStatusMethodNotAllowed = stderrors.New("405 - Method Not Allowed - 接口访问的 Method 不正确,比如应该使用 POST 的接口使用了 GET 访问等,客户端需要检查接口访问方式是否正确。")
	// ErrStatusInternalServerError 500 - Internal Server Error
	ErrStatusInternalServerError = stderrors.New("500 - Internal Server Error - 其它类型的错误默认都会返回 500,对这类错误如果应用无法根据提示信息找到原因的话,可以找 Apollo 研发团队一起排查问题。")
)

Functions

func NormalizeNamespace

func NormalizeNamespace(ns string) string

NormalizeNamespace 规范化命名空间格式

func NormalizeURL

func NormalizeURL(url string) string

NormalizeURL 规范化 url 格式

func TrimFormat

func TrimFormat(namespace string) string

TrimFormat 去除命名空间格式

Types

type APIOption

type APIOption func(o *apiOption)

APIOption 接口可选参数配置

func WithAppID

func WithAppID(appID string) APIOption

WithAppID 设置应用ID

func WithCluster

func WithCluster(cluster string) APIOption

WithCluster 设置集群

func WithEnv

func WithEnv(env string) APIOption

WithEnv 设置环境

func WithNamespace

func WithNamespace(namespace string) APIOption

WithNamespace 设置命名空间

type AddItemRequest

type AddItemRequest struct {
	Key                 string `json:"key"`                 // 配置的 key,长度不能超过 128 个字符。非 properties 格式,key 固定为 content
	Value               string `json:"value"`               // 配置的 value,长度不能超过 20000 个字符,非 properties 格式,value 为文件全部内容
	Comment             string `json:"comment"`             // 配置的备注,长度不能超过 1024 个字符(非必填)
	DataChangeCreatedBy string `json:"dataChangeCreatedBy"` // item 的创建人,格式为域账号,也就是 sso 系统的 UserId
}

AddItemRequest 添加配置信息请求

type ClientConfig

type ClientConfig struct {
	PortalAddress    string // 入口地址,一般端口为 8070
	Token            string // 鉴权令牌,须事先在管理平台注册并授权
	DefaultEnv       string `json:",default=DEV"` // 默认环境,一般为 DEV
	DefaultAppID     string // 默认应用ID
	DefaultCluster   string `json:",default=default"` // 默认集群,一般为 default
	DefaultNamespace string `json:",optional"`        // 默认命名空间
}

ClientConfig 默认阿波罗配置中心开放平台客户端配置 https://github.com/apolloconfig/apollo/blob/master/docs/zh/portal/apollo-open-api-platform.md#31-url%E8%B7%AF%E5%BE%84%E5%8F%82%E6%95%B0%E8%AF%B4%E6%98%8E

type ClientOption

type ClientOption func(c *client)

ClientOption 阿波罗配置中心开放平台客户端可选配置

func WithHTTPClient

func WithHTTPClient(hc *http.Client) ClientOption

WithHTTPClient 使用配置的 HTTP 客户端

type CreateNamespaceRequest

type CreateNamespaceRequest struct {
	Name                string `json:"name"`                // namespace 的名字
	AppID               string `json:"appId"`               // namespace 所属的 AppId
	Format              Format `json:"format"`              // namespace 的格式,只能是以下类型:properties、xml、json、yml 和 yaml
	IsPublic            bool   `json:"isPublic"`            // 是否是公共文件
	Comment             string `json:"comment"`             // namespace 说明(非必填)
	DataChangeCreatedBy string `json:"dataChangeCreatedBy"` // namespace 的创建人,格式为域账号,也就是 sso 系统的 UserId
}

CreateNamespaceRequest 创建命名空间请求

type CreateNamespaceResponse

type CreateNamespaceResponse struct {
	Name                       string `json:"name"`
	AppID                      string `json:"appId"`
	Format                     string `json:"format"`
	IsPublic                   bool   `json:"isPublic"`
	Comment                    string `json:"comment"`
	DataChangeCreatedBy        string `json:"dataChangeCreatedBy"`
	DataChangeLastModifiedBy   string `json:"dataChangeLastModifiedBy"`
	DataChangeCreatedTime      string `json:"dataChangeCreatedTime"`
	DataChangeLastModifiedTime string `json:"dataChangeLastModifiedTime"`
}

CreateNamespaceResponse 创建命名空间响应

type DeleteItemRequest

type DeleteItemRequest struct {
	Key      string `json:"key"`      // 配置的 key。非 properties 格式,key 固定为 content
	Operator string `json:"operator"` // 删除配置的操作者,域账号
}

DeleteItemRequest 删除配置信息请求

type EnvClusters

type EnvClusters struct {
	Env      string   `json:"env"`
	Clusters []string `json:"clusters"`
}

EnvClusters 环境及其下集群信息

type Format

type Format string

Format 命名空间格式

const (
	// FormatProperties 命名空间格式:properties
	FormatProperties Format = "properties"
	// FormatXML 命名空间格式:xml
	FormatXML Format = "xml"
	// FormatYML 命名空间格式:yml
	FormatYML Format = "yml"
	// FormatYAML 命名空间格式:yaml
	FormatYAML Format = "yaml"
	// FormatJSON 命名空间格式:json
	FormatJSON Format = "json"
)

func ParseFormat

func ParseFormat(namespace string) (Format, bool)

ParseFormat 解析命名空间格式

type Item

type Item struct {
	Key                        string `json:"key"`
	Value                      string `json:"value"`
	Comment                    string `json:"comment"`
	DataChangeCreatedBy        string `json:"dataChangeCreatedBy"`
	DataChangeLastModifiedBy   string `json:"dataChangeLastModifiedBy"`
	DataChangeCreatedTime      string `json:"dataChangeCreatedTime"`
	DataChangeLastModifiedTime string `json:"dataChangeLastModifiedTime"`
}

Item 配置信息

type Namespace

type Namespace struct {
	AppID                      string `json:"appId"`
	ClusterName                string `json:"clusterName"`
	NamespaceName              string `json:"namespaceName"`
	Comment                    string `json:"comment"`
	Format                     string `json:"format"`
	IsPublic                   bool   `json:"isPublic"`
	Items                      []Item `json:"items"`
	DataChangeCreatedBy        string `json:"dataChangeCreatedBy"`
	DataChangeLastModifiedBy   string `json:"dataChangeLastModifiedBy"`
	DataChangeCreatedTime      string `json:"dataChangeCreatedTime"`
	DataChangeLastModifiedTime string `json:"dataChangeLastModifiedTime"`
}

Namespace 命名空间信息

type NamespaceLock

type NamespaceLock struct {
	NamespaceName string `json:"namespaceName"`
	IsLocked      bool   `json:"isLocked"`
	LockedBy      string `json:"lockedBy"`
}

NamespaceLock 命名空间锁定信息

type OpenAPI

type OpenAPI interface {
	// GetEnvClusters 获取对应应用环境下的所有集群信息(appId 必填)
	// https://github.com/apolloconfig/apollo/blob/master/docs/zh/portal/apollo-open-api-platform.md#321-%E8%8E%B7%E5%8F%96app%E7%9A%84%E7%8E%AF%E5%A2%83%E9%9B%86%E7%BE%A4%E4%BF%A1%E6%81%AF
	GetEnvClusters(ctx context.Context, opts ...APIOption) ([]*EnvClusters, error)
	// GetNamespaces 获取对应集群下的所有命名空间信息(env、appId 和 cluster 必填)
	// https://github.com/apolloconfig/apollo/blob/master/docs/zh/portal/apollo-open-api-platform.md#325-%E8%8E%B7%E5%8F%96%E9%9B%86%E7%BE%A4%E4%B8%8B%E6%89%80%E6%9C%89namespace%E4%BF%A1%E6%81%AF%E6%8E%A5%E5%8F%A3
	GetNamespaces(ctx context.Context, opts ...APIOption) ([]*Namespace, error)
	// GetNamespace 获取指定命名空间信息(env、appId、cluster 和 namespace 必填)
	// https://github.com/apolloconfig/apollo/blob/master/docs/zh/portal/apollo-open-api-platform.md#326-%E8%8E%B7%E5%8F%96%E6%9F%90%E4%B8%AAnamespace%E4%BF%A1%E6%81%AF%E6%8E%A5%E5%8F%A3
	GetNamespace(ctx context.Context, opts ...APIOption) (*Namespace, error)
	// CreateNamespace 创建命名空间信息(appId 必填)
	// https://github.com/apolloconfig/apollo/blob/master/docs/zh/portal/apollo-open-api-platform.md#327-%E5%88%9B%E5%BB%BAnamespace
	CreateNamespace(ctx context.Context, r *CreateNamespaceRequest, opts ...APIOption) (*CreateNamespaceResponse, error)
	// GetNamespaceLock 获取指定命名空间锁定信息(env、appId、cluster 和 namespace 必填)
	// https://github.com/apolloconfig/apollo/blob/master/docs/zh/portal/apollo-open-api-platform.md#328-%E8%8E%B7%E5%8F%96%E6%9F%90%E4%B8%AAnamespace%E5%BD%93%E5%89%8D%E7%BC%96%E8%BE%91%E4%BA%BA%E6%8E%A5%E5%8F%A3
	GetNamespaceLock(ctx context.Context, opts ...APIOption) (*NamespaceLock, error)
	// AddItem 添加配置信息(env、appId、cluster 和 namespace 必填)
	// https://github.com/apolloconfig/apollo/blob/master/docs/zh/portal/apollo-open-api-platform.md#3210-%E6%96%B0%E5%A2%9E%E9%85%8D%E7%BD%AE%E6%8E%A5%E5%8F%A3
	AddItem(ctx context.Context, r *AddItemRequest, opts ...APIOption) (*Item, error)
	// UpdateItem 更新配置信息(env、appId、cluster 和 namespace 必填)
	// https://github.com/apolloconfig/apollo/blob/master/docs/zh/portal/apollo-open-api-platform.md#3211-%E4%BF%AE%E6%94%B9%E9%85%8D%E7%BD%AE%E6%8E%A5%E5%8F%A3
	UpdateItem(ctx context.Context, r *UpdateItemRequest, opts ...APIOption) error
	// CreateOrUpdateItem 创建或者更新配置信息(env、appId、cluster 和 namespace 必填)
	// https://github.com/apolloconfig/apollo/blob/master/docs/zh/portal/apollo-open-api-platform.md#3211-%E4%BF%AE%E6%94%B9%E9%85%8D%E7%BD%AE%E6%8E%A5%E5%8F%A3
	CreateOrUpdateItem(ctx context.Context, r *UpdateItemRequest, opts ...APIOption) error
	// DeleteItem 删除配置信息(env、appId、cluster 和 namespace 必填)
	// https://github.com/apolloconfig/apollo/blob/master/docs/zh/portal/apollo-open-api-platform.md#3212-%E5%88%A0%E9%99%A4%E9%85%8D%E7%BD%AE%E6%8E%A5%E5%8F%A3
	DeleteItem(ctx context.Context, r *DeleteItemRequest, opts ...APIOption) error
	// PublishRelease 发布版本配置信息(env、appId、cluster 和 namespace 必填)
	// https://github.com/apolloconfig/apollo/blob/master/docs/zh/portal/apollo-open-api-platform.md#3213-%E5%8F%91%E5%B8%83%E9%85%8D%E7%BD%AE%E6%8E%A5%E5%8F%A3
	PublishRelease(ctx context.Context, r *PublishReleaseRequest, opts ...APIOption) (*Release, error)
	// GetRelease 获取版本配置信息(env、appId、cluster 和 namespace 必填)
	// https://github.com/apolloconfig/apollo/blob/master/docs/zh/portal/apollo-open-api-platform.md#3214-%E8%8E%B7%E5%8F%96%E6%9F%90%E4%B8%AAnamespace%E5%BD%93%E5%89%8D%E7%94%9F%E6%95%88%E7%9A%84%E5%B7%B2%E5%8F%91%E5%B8%83%E9%85%8D%E7%BD%AE%E6%8E%A5%E5%8F%A3
	GetRelease(ctx context.Context, opts ...APIOption) (*Release, error)
}

OpenAPI 阿波罗配置中心开放平台接口

func MustNewClient

func MustNewClient(config ClientConfig, opts ...ClientOption) OpenAPI

MustNewClient 新建阿波罗配置中心开放平台客户端

func NewClient

func NewClient(config ClientConfig, opts ...ClientOption) (OpenAPI, error)

NewClient 新建阿波罗配置中心开放平台客户端

type PublishReleaseRequest

type PublishReleaseRequest struct {
	ReleaseTitle   string `json:"releaseTitle"`   // 此次发布的标题,长度不能超过 64 个字符
	ReleaseComment string `json:"releaseComment"` // 发布的备注,长度不能超过 256 个字符(非必填)
	ReleasedBy     string `json:"releasedBy"`     // 发布人,域账号,注意:如果 ApolloConfigDB.ServerConfig 中的 namespace.lock.switch 设置为 true 的话(默认是 false),那么该环境不允许发布人和编辑人为同一人。所以如果编辑人是 zhanglea,发布人就不能再是 zhanglea。
}

PublishReleaseRequest 发布版本配置信息请求

type Release

type Release struct {
	AppID                      string            `json:"appId"`
	ClusterName                string            `json:"clusterName"`
	NamespaceName              string            `json:"namespaceName"`
	Name                       string            `json:"name"`
	Configurations             map[string]string `json:"configurations"`
	Comment                    string            `json:"comment"`
	DataChangeCreatedBy        string            `json:"dataChangeCreatedBy"`
	DataChangeLastModifiedBy   string            `json:"dataChangeLastModifiedBy"`
	DataChangeCreatedTime      string            `json:"dataChangeCreatedTime"`
	DataChangeLastModifiedTime string            `json:"dataChangeLastModifiedTime"`
}

Release 版本配置信息

type UpdateItemRequest

type UpdateItemRequest struct {
	Key                      string `json:"key"`                      // 配置的 key,需和 url 中的 key 值一致。非 properties 格式,key 固定为content
	Value                    string `json:"value"`                    // 配置的 value,长度不能超过 20000 个字符,非 properties 格式,value 为文件全部内容
	Comment                  string `json:"comment"`                  // 配置的备注,长度不能超过 256 个字符(非必填)
	DataChangeLastModifiedBy string `json:"dataChangeLastModifiedBy"` // item 的修改人,格式为域账号,也就是 sso 系统的 UserId
	DataChangeCreatedBy      string `json:"dataChangeCreatedBy"`      // 当 createIfNotExists 为 true 时必选。item 的创建人,格式为域账号,也就是 sso 系统的 userID
}

UpdateItemRequest 更新配置信息请求

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL