common_endpoints

package
v1.67.1 Latest Latest
Warning

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

Go to latest
Published: Apr 23, 2026 License: MIT Imports: 3 Imported by: 0

README

Package common_endpoints

Пакет common_endpoints предназначен для формирования набора стандартных (общих) эндпоинтов сервиса.

Types

CommonEndpointOption

Тип CommonEndpointOption представляет собой функциональную опцию для конфигурации набора общих эндпоинтов.

Используется для модификации внутренней конфигурации commonEndpointsCfg.

type CommonEndpointOption func(cfg *commonEndpointsCfg)

Functions

CommonEndpoints(basePath string, opts ...CommonEndpointOption) []cluster.EndpointDescriptor

Создаёт и возвращает список cluster.EndpointDescriptor на основе переданных опций.

  • basePath — базовый путь для всех создаваемых эндпоинтов.
  • opts — набор опций конфигурации (например, добавление swagger-endpoint).
WithSwaggerEndpoint(swagger []byte) CommonEndpointOption

Добавляет endpoint для получения Swagger-спецификации.

  • swagger — содержимое swagger-файла в виде []byte, если он пустой, endpoint не будет добавлен.
  • Данные автоматически кодируются в Base64 перед возвратом клиенту.

Endpoint будет доступен по пути:

{basePath}/swagger

и будет иметь параметры:

  • HTTP метод: GET
  • UserAuthRequired = false
  • Inner = false

Internal behavior

Swagger endpoint

Swagger endpoint формируется функцией swaggerEndpoint и возвращает cluster.EndpointDescriptor со следующими характеристиками:

  • Path: basePath + "/swagger"
  • Handler: возвращает Base64-кодированную строку swagger-файла
  • Не требует аутентификации пользователя
  • Использует метод GET

Usage

Default usage flow
package main

import (
	"os"

	"github.com/txix-open/isp-kit/cluster"
	"github.com/txix-open/isp-kit/common_endpoints"
)

func main() {
	swaggerBytes, _ := os.ReadFile("swagger.json")

	endpoints := common_endpoints.CommonEndpoints(
		"/api",
		common_endpoints.WithSwaggerEndpoint(swaggerBytes),
	)

	var descriptors []cluster.EndpointDescriptor
	descriptors = append(descriptors, endpoints...)

	// передаём descriptors в config сервис/router
}
Without swagger endpoint
endpoints := common_endpoints.CommonEndpoints("/api")
// endpoints будет пустым

Documentation

Overview

Package common_endpoints provides common HTTP endpoint descriptors for services. It offers a simple way to register standard endpoints like Swagger documentation.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CommonEndpoints

func CommonEndpoints(basePath string, opts ...CommonEndpointOption) []cluster.EndpointDescriptor

CommonEndpoints creates a slice of cluster.EndpointDescriptor for common service endpoints. It accepts a basePath for URL path prefix and variadic CommonEndpointOption functions to configure endpoints. Returns a slice of endpoint descriptors that can be registered with a cluster router. Currently supports Swagger documentation endpoint when configured via WithSwaggerEndpoint.

Types

type CommonEndpointOption

type CommonEndpointOption func(cfg *commonEndpointsCfg)

CommonEndpointOption is a functional option for configuring commonEndpointsCfg.

func WithSwaggerEndpoint

func WithSwaggerEndpoint(swagger []byte) CommonEndpointOption

WithSwaggerEndpoint configures the CommonEndpoints builder to include a Swagger endpoint. The swagger parameter should contain the JSON-formatted Swagger specification. The endpoint is exposed at {basePath}/swagger and is accessible via HTTP GET.

Jump to

Keyboard shortcuts

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