Categorygithub.com/Gemini-Commerce/go-client-urlmanager
repositorypackage
0.0.0-20241118164434-e61318157b9d
Repository: https://github.com/gemini-commerce/go-client-urlmanager.git
Documentation: pkg.go.dev

# README

Go API client for urlmanager

The URL Manager service provides a set of APIs for managing URL rewrites within your application. URL rewriting is a technique used to modify the appearance or structure of URLs while maintaining the functionality and accessibility of the underlying resources.

The URL Manager service offers various operations to create, retrieve, update, and delete URL rewrite configurations. These configurations allow you to define rules that map incoming URLs to different paths or destinations based on specific criteria. By using URL rewriting, you can enhance the user experience, improve SEO (Search Engine Optimization), and manage complex URL structures effectively.

To get started with the URL Manager service, you need to integrate the provided Proto API into your application. The API supports various programming languages and frameworks, making it easy to incorporate URL rewriting functionality into your existing codebase.

Once integrated, you can utilize the different API methods to create, manage, and query URL rewrite configurations based on your application's requirements.

Refer to the API documentation for detailed information on the request and response formats, authentication requirements, and example usage of each API method.

Overview

This API client was generated by the OpenAPI Generator project. By using the OpenAPI-spec from a remote server, you can easily generate an API client.

  • API version: 1.0.0
  • Package version: 1.0.0
  • Generator version: 7.9.0
  • Build package: org.openapitools.codegen.languages.GoClientCodegen

Installation

Install the following dependencies:

go get github.com/stretchr/testify/assert
go get golang.org/x/oauth2
go get golang.org/x/net/context

Put the package under your project folder and add the following in import:

import urlmanager "github.com/Gemini-Commerce/go-client-urlmanager"

To use a proxy, set the environment variable HTTP_PROXY:

os.Setenv("HTTP_PROXY", "http://proxy_name:proxy_port")

Configuration of Server URL

Default configuration comes with Servers field that contains server objects as defined in the OpenAPI specification.

Select Server Configuration

For using other server than the one defined on index 0 set context value urlmanager.ContextServerIndex of type int.

ctx := context.WithValue(context.Background(), urlmanager.ContextServerIndex, 1)

Templated Server URL

Templated server URL is formatted using default variables from configuration or from context value urlmanager.ContextServerVariables of type map[string]string.

ctx := context.WithValue(context.Background(), urlmanager.ContextServerVariables, map[string]string{
	"basePath": "v2",
})

Note, enum values are always validated and all unused variables are silently ignored.

URLs Configuration per Operation

Each operation can use different server URL defined using OperationServers map in the Configuration. An operation is uniquely identified by "{classname}Service.{nickname}" string. Similar rules for overriding default operation server index and variables applies by using urlmanager.ContextOperationServerIndices and urlmanager.ContextOperationServerVariables context maps.

ctx := context.WithValue(context.Background(), urlmanager.ContextOperationServerIndices, map[string]int{
	"{classname}Service.{nickname}": 2,
})
ctx = context.WithValue(context.Background(), urlmanager.ContextOperationServerVariables, map[string]map[string]string{
	"{classname}Service.{nickname}": {
		"port": "8443",
	},
})

Documentation for API Endpoints

All URIs are relative to https://urlmanager.api.gogemini.io

ClassMethodHTTP requestDescription
BasicOperationsAPIUrlManagerChangeUrlRewriteRequestPathPost /urlmanager/change_url_rewrite_request_pathChange Url Rewrite Request Path
BasicOperationsAPIUrlManagerChangeUrlRewriteRequestPath2Post /urlmanager.UrlManager/ChangeUrlRewriteRequestPathChange Url Rewrite Request Path
BasicOperationsAPIUrlManagerCreateUrlRewritePost /urlmanager/create_url_rewriteCreate Url Rewrite
BasicOperationsAPIUrlManagerCreateUrlRewrite2Post /urlmanager.UrlManager/CreateUrlRewriteCreate Url Rewrite
BasicOperationsAPIUrlManagerDeleteUrlRewritePost /urlmanager/delete_url_rewriteDelete Url Rewrite
BasicOperationsAPIUrlManagerDeleteUrlRewrite2Post /urlmanager.UrlManager/DeleteUrlRewriteDelete Url Rewrite
BasicOperationsAPIUrlManagerGetUrlRewritePost /urlmanager/get_url_rewriteGet Url Rewrite
BasicOperationsAPIUrlManagerGetUrlRewrite2Post /urlmanager.UrlManager/GetUrlRewriteGet Url Rewrite
BasicOperationsAPIUrlManagerListUrlRewritesPost /urlmanager/list_url_rewritesList Url Rewrites
BasicOperationsAPIUrlManagerListUrlRewrites2Post /urlmanager.UrlManager/ListUrlRewritesList Url Rewrites
BasicOperationsAPIUrlManagerListUrlRewritesByTargetPathsPost /urlmanager/list_url_rewrites_by_target_pathsList Url Rewrites By Target Paths
BasicOperationsAPIUrlManagerListUrlRewritesByTargetPaths2Post /urlmanager.UrlManager/ListUrlRewritesByTargetPathsList Url Rewrites By Target Paths
BasicOperationsAPIUrlManagerResolveUrlRewritePost /urlmanager/resolve_url_rewriteResolve Url Rewrite
BasicOperationsAPIUrlManagerResolveUrlRewrite2Post /urlmanager.UrlManager/ResolveUrlRewriteResolve Url Rewrite

Documentation For Models

Documentation For Authorization

Authentication schemes defined for the API:

Authorization

  • Type: API key
  • API key parameter name: Authorization
  • Location: HTTP header

Note, each API key must be added to a map of map[string]APIKey where the key is: Authorization and passed in as the auth context for each request.

Example

auth := context.WithValue(
		context.Background(),
		urlmanager.ContextAPIKeys,
		map[string]urlmanager.APIKey{
			"Authorization": {Key: "API_KEY_STRING"},
		},
	)
r, err := client.Service.Operation(auth, args)

standardAuthorization

  • Type: OAuth
  • Flow: implicit
  • Authorization URL:
  • Scopes: N/A

Example

auth := context.WithValue(context.Background(), urlmanager.ContextAccessToken, "ACCESSTOKENSTRING")
r, err := client.Service.Operation(auth, args)

Or via OAuth2 module to automatically refresh tokens and perform user authentication.

import "golang.org/x/oauth2"

/* Perform OAuth2 round trip request and obtain a token */

tokenSource := oauth2cfg.TokenSource(createContext(httpClient), &token)
auth := context.WithValue(oauth2.NoContext, urlmanager.ContextOAuth2, tokenSource)
r, err := client.Service.Operation(auth, args)

Documentation for Utility Methods

Due to the fact that model structure members are all pointers, this package contains a number of utility functions to easily obtain pointers to values of basic types. Each of these functions takes a value of the given basic type and returns a pointer to it:

  • PtrBool
  • PtrInt
  • PtrInt32
  • PtrInt64
  • PtrFloat
  • PtrFloat32
  • PtrFloat64
  • PtrString
  • PtrTime

Author

[email protected]