Categorygithub.com/api7/cloud-go-sdk
modulepackage
0.0.0-20230426082534-e99f8854ef3b
Repository: https://github.com/api7/cloud-go-sdk.git
Documentation: pkg.go.dev

# README

cloud-go-sdk

The Go SDK for accessing API7 Cloud API

Installation

Make sure you're using Go Modules to manage your Go Project, and your Go version needs to be 1.19 or later.

go mod init

Then, import the cloud-go-sdk in your Go program by running:

import (
	"github.com/api7/cloud-go-sdk"
)

Alternatively, download the cloud-go-sdk by running:

go get -u github.com/api7/cloud-go-sdk

Mock

You may want to add unit test cases after you import cloud-go-sdk into your Go program, for the sake of better integration, cloud-go-sdk uses mockgen to generate mock implementations.

e.g., for the Interface, we have a MockInterface implementation. If you want to mock an Application create error, you can write some codes like:

ctrl := gomock.NewController(t) // var t *testing.T
cloud := NewMockInterface(ctrl)
cloud.EXPECT().CreateApplication(gomock.Any(), &Application{
    ApplicationSpec: ApplicationSpec{
        Name:        "test app",
		Description: "This is a test app",
           Protocols:   []string{ProtocolHTTP},
           PathPrefix:  "/api/v1",
           Hosts:       []string{"app.test.com"},
           Upstreams: []UpstreamAndVersion{
			{
				Upstream: Upstream{
					Scheme: "https",
					LBType: "roundrobin",
					Targets: []UpstreamTarget{
						{
							Host:   "10.0.5.1", 
							Port:   80,
							Weight: 100,
						},
						{
							Host:   "10.0.5.2",
							Port:   80,
							Weight: 100,
						},
					},
				}, 
				Version: "default",
			},
		   }, 
		   DefaultUpstreamVersion: "default", 
		   Active:                 ActiveStatus,
	},
}, &ApplicationCreateOptions{
	Cluster: &Cluster{
		ID: 1,
	},
}).Return(nil, errors.New("mock error"))

Development

Run test cases via running:

make test

Regenerate mock codes by running:

make mockgen

# Functions

No description provided by the author
NewIDGenerator returns an IDGenerator object.
NewInterface creates an Interface object.
NewMockhttpClient creates a new mock instance.
NewMockInterface creates a new mock instance.

# Constants

ActiveStatus indicates an object is active, and this object will be seen by gateway instances.
Any means any status.
APITypeRest indicates this is a Rest API.
APITypeWebSocket indicates this is a Websocket API.
CanaryReleaseStateFinished indicates the finish state of CanaryRelease.
CanaryReleaseStateInProgress indicates the in_progress state of CanaryRelease.
CanaryReleaseStatePaused indicates the pause state of CanaryRelease.
CanaryReleaseTypePercent means using percent to do canary release.
CanaryReleaseTypeRule means using rule match to do canary release.
ClientCertificate means client-type certificate.
ClusterCreateFailed means a cluster was not created successfully.
ClusterCreating means a cluster is being created.
ClusterDeleted means a cluster was deleted.
ClusterDeleting means a cluster is being deleted.
ClusterNormal means a cluster was created, and now it's normal.
ClusterPending means a cluster is not created yet.
CookieSubject indicates the expression subject is from Cookie header.
Deleted indicates the entity has been deleted.
DeleteURITailSlash means delete the tail slash of the request uri before matching.
EqualOperator indicates the expression operator is "equal".
GatewayInstanceHealthy indicates the instance is healthy.
GatewayInstanceLostConnection indicate the instance lose heartbeat in short time(between InstanceLostConnectionThresholdDuration and InstanceOfflineThresholdDuration).
GatewayInstanceOffline indicates the instance loses heartbeat for long time(out-of the InstanceLiveThresholdDuration).
GatewayInstanceOnlyHeartbeats indicates the instance sends heartbeat probes periodically but the configuration cannot be delivered to the instance.
HeaderSubject indicates the expression subject is from a HTTP request header.
HealthCheckTypeHTTP indicates an HTTP-type health check.
HealthCheckTypeHTTPS indicates an HTTPS-type health check.
HealthCheckTypeTCP indicates a TCP-type health check.
HideVersionToken means hide the APISIX version info in the Server header.
InactiveStatus indicates an object is inactive, and this object won't be seen by gateway instances.
LargerEqualOperator indicates the expression operator is "larger_equal".
LargerThanOperator indicates the expression operator is "larger_than".
LessEqualOperator indicates the expression operator is "less_equal".
LessThanOperator indicates the expression operator is "less_than".
LoadBalanceConsistentHash indicates the consistent hash load balancing algorithm.
LoadBalanceEWMA indicates the ewma load balancing algorithm.
LoadBalanceLeastConn indicates the least connection load balancing algorithm.
LoadBalanceRoundRobin indicates the weighted round robin load balancing algorithm.
MatchAll meaning all the expressions should be matched.
MatchAny meaning any of the expressions should be matched.
MemberStateActive means the member is active.
MemberStatePending means the member is still in pending state.
Normal indicates that the entity and associated resources are ready.
NotEqualOperator indicates the expression operator is "not_equal".
NotPresentOperator indicates the expression operator is "not_present".
PathExactMatch means the requests' URL path has to be same to the API path.
PathPrefixMatch means the requests' URL path leads with the API path will match this API;.
PathSubject indicates the expression subject is from the URI path.
PresentOperator indicates the expression operator is "present".
ProtocolHTTP indicates the HTTP protocol.
ProtocolHTTPS indicates the HTTPS protocol.
QuerySubject indicates the expression subject is from the HTTP query string.
RealIPPositionCookie indicates the real ip is in cookie.
RealIPPositionHeader indicates the real ip is in an HTTP header.
RealIPPositionQuery indicates the real ip is in a query string.
RegexMatchOperator indicates the expression operator is "regex_match".
RegexNotMatchOperator indicates the expression operator is "regex_not_match".
RewriteServerHeader means rewrite the Server header in the response.
RoleScopeCluster indicates a cluster scoped role.
RoleScopeOrganization indicates an organization scoped role.
ServerCertificate means server-type certificate.
ServiceRegistryKubernetes indicates the kubernetes-type service registry.
Uninitialized represents the entity has been saved to the db, but the associated resource has not yet been ready.
UpstreamSchemeHTTP indicates the http scheme for communicating with upstream.
UpstreamSchemeHTTPS indicates the https scheme for communicating with upstream.
VariableSubject indicates the expression subject is a Nginx or APISIX variable.

# Variables

No description provided by the author
DefaultOptions contains the default settings for all the options.
DefaultPagination is the default paging.
No description provided by the author
ErrEmptyToken indicates the access token value is empty.
HTTPLogCollection means http log collection.
KakfaLogCollection means kafka log collection.

# Structs

AccessLogRotateSettings is the access log rotate settings config.
AccessToken is the token used by API7 Cloud to authenticate clients.
ActiveHealthCheck the data of active health check.
API is the definition of API7 Cloud API, which also contains some management fields.
APIPath is the path definition for an API.
APIProxySettings is the api proxy settings config.
APISpec is the specification of the API.
Application is the definition of API7 Cloud Application, which also contains some management fields.
ApplicationSpec is the specification of the Application.
CanaryRelease is the definition of API7 Cloud CanaryRelease.
CanaryReleaseRule is the rule that used in canary release.
CanaryReleaseSpec is the specification of the CanaryRelease.
Certificate is the definition of API7 Cloud Certificate, which also contains some management fields.
CertificateDetails contains the details of the user uploaded certificate.
CertificateMetadata contains the metadata of an user uploaded certificate.
CertificateSpec is the specification of the Certificate.
Checks the data of health check.
ClientIPReplaceFrom is the client ip replace from config.
ClientRealIPConfig is the client real ip config.
ClientSettings is the client settings config.
Cluster contains the cluster specification and management fields.
ClusterSettings is cluster settings.
ClusterSpec is the specification of cluster.
Consumer is an abstraction of Application/API caller.
Expression is the route match expressions.
Filter indicates conditions to filter out list results.
FineGrainedRouteControl is fine grained route control settings.
GatewayInstance shows the gateway instance (Apache APISIX) status.
GatewayInstancePayload contains basic information for a gateway instance.
HTTPActiveHealthCheck is the configuration of HTTP active health check.
HTTPHealthyPredicates healthy predicates.
HTTPHealthyPredicatesForPassive healthy predicates for passive health check.
HTTPPassiveHealthCheck is the configuration of HTTP passive health check.
HTTPSActiveHealthCheck the data of active health check for https.
HTTPUnhealthyPredicates unhealthy predicates.
HTTPUnhealthyPredicatesForPassive unhealthy predicates for passive health check.
KubernetesAPIServer is configuration for the Kubernetes API server.
KubernetesEndpointsLabelSelector is the label selector of kubernetes service discovery.
KubernetesNamespaceSelector is the namespace selector of kubernetes service discovery.
KubernetesServiceRegistry is the Kubernetes registry.
KubernetesUpstreamServiceDiscovery is the kubernetes service discovery of the upstream.
LogCollection is the abstraction of log storage.
Member is the member of organization.
MemberSpec contains the information.
Methods means the operations that can be performed on an organization.
MetricsConfig contains configurations related to metrics.
MockhttpClient is a mock of httpClient interface.
MockhttpClientMockRecorder is the mock recorder for MockhttpClient.
MockInterface is a mock of Interface interface.
MockInterfaceMockRecorder is the mock recorder for MockInterface.
ObservabilitySettings is the observability settings config.
Options contains all related configurations for the SDK to communicate with API7 Cloud.
Organization is the specification of an API7 Cloud organization.
Pagination indicates the paging.
PassiveHealthCheck the data of passive health check.
Permissions means the permissions that can be performed on an organization.
Region is the specification of the deploy region for Cloud.
ResourceCreateOptions contains some options for creating an API7 Cloud resource.
ResourceDeleteOptions contains some options for deleting an API7 Cloud resource.
ResourceGetOptions contains some options for getting an API7 Cloud resource.
ResourceListOptions contains some options for listing the same kind of API7 Cloud resources.
ResourceUpdateOptions contains some options for updating an API7 Cloud resource.
Role is the role of a member.
RoleBinding binds a role to an organization member.
ServerHeaderCustomization is the server header customization settings.
ServiceRegistry attaches some management field to ServiceRegistry.
ServiceRegistrySpec is the service registry specification.
TCPActiveCheckPredicates predicates for the TCP probe active health check.
TCPHealthyPredicates the healthy case data of tcp health check.
TCPPassiveCheckPredicates predicates for the TCP probe passive health check.
TCPUnhealthyPredicates the unhealthy case data of tcp health check.
TCPUnhealthyPredicatesForPassive the unhealthy case data of passive tcp health check.
TLSBundle contains a pair of certificate, private key, and the issuing certificate.
TraceEvent indicates an event occurred during the communication with API7 Cloud.
TraceSeries contains a series of events (ordered by their happening time).
Upstream is the definition of the upstream on Application.
UpstreamAndVersion contains both the upstream definition and the version information.
UpstreamServiceDiscovery is the service discovery of the upstream.
UpstreamTarget is the definition for an upstream endpoint.
UpstreamTimeout is the timeout for connecting to, and sending and receiving messages to and from the Upstream, value in seconds.
User defines user information for API7 Cloud.

# Interfaces

APIInterface is the interface for manipulating API.
APIListIterator is an iterator for listing APIs.
ApplicationInterface is the interface for manipulating Applications.
ApplicationListIterator is an iterator for listing Applications.
AuthInterface is the interface for the authentication process with API7 Cloud.
CanaryReleaseInterface is the interface for manu.
CanaryReleaseListIterator is an iterator for listening CanaryReleases.
CertificateInterface is the interface for manipulating Certificates.
CertificateListIterator is an iterator for listing Certificates.
ClusterInterface is the interface for manipulating cluster.
ClusterListIterator is an iterator for listing clusters.
ConsumerInterface is the interface for manipulating Consumers.
ConsumerListIterator is an iterator for listing Consumers.
IDGenerator is an interface for generating IDs.
Interface is the entrypoint of the Cloud Go SDK.
LogCollectionInterface is the interface of the LogCollection.
LogCollectionIterator is an iterator for listing Log Collections.
MemberListIterator is an iterator for listing Members.
OrganizationInterface is the interface for manipulating Organization and Member.
RegionInterface is the interface for manipulating Region.
RegionListIterator is an iterator for listing Regions.
No description provided by the author
RoleListIterator is an iterator for listing Roles.
ServiceDiscoveryInterface is the interface for manipulating API7 Cloud service discovery features.
ServiceRegistryListIterator is an iterator for listing service registries.
TraceInterface is the interface for http trace.
UserInterface is the interface for the user-related process on API7 Cloud.

# Type aliases

CertificateType is the type of log collection.
ClusterStage is used to depict different cluster lifecycles.
EntityStatus is common status definition for any kind of entity: * Uninitialized represents the entity has been saved to the db, but the associated resource has not yet been ready.
ExpressionLogicalRelationship is the logical relationship between expressions.
ExpressionOperator is the operator of the expression.
ExpressionSubject is the subject category of the expression.
GatewayInstanceStatus is the status of an gateway instance.
ID is the type of the id field used for any entities.
LogCollectionType is the type of log collection.
Plugins contains a collect of plugins like CORS, Rate Limiting, Authentication and so on.
ProbeHeader indicates headers that will be taken in probe requests.
ServiceRegistryType describes the type of service registry.