api

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: May 3, 2026 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RegisterHealth

func RegisterHealth(api huma.API)

RegisterHealth はヘルスチェックエンドポイントを登録する。 このエンドポイントは Cloud Run のヘルスチェック互換を想定しており、 レートリミットやボディサイズ制限の影響を受けないようミドルウェア側の exempt path 設定で除外される前提で利用される。 想定外エラーが発生しない設計のため commonErrorCodes() は適用しない。

func RegisterRoutes

func RegisterRoutes(api huma.API, compressHandler *handler.CompressHandler, convertHandler *handler.ConvertHandler)

RegisterRoutes はAPIルートを登録する。

Types

type CORSConfig

type CORSConfig struct {
	AllowedOrigins   []string
	AllowedMethods   []string
	AllowedHeaders   []string
	AllowCredentials bool
	MaxAge           int
}

CORSConfig はCORSミドルウェアの設定を表す。

type Config

type Config struct {
	Host              string
	Port              int
	ShutdownTimeout   time.Duration
	ReadHeaderTimeout time.Duration
	ReadTimeout       time.Duration
	WriteTimeout      time.Duration
	IdleTimeout       time.Duration

	CORS           CORSConfig
	BodyLimitBytes int64
	RateLimit      RateLimitConfig
	Logging        LoggingConfig
}

Config はAPIサーバーの設定を保持する。

func DefaultConfig

func DefaultConfig() Config

DefaultConfig はデフォルト設定を返す。

func LoadConfig

func LoadConfig(opts LoadConfigOptions) (Config, error)

LoadConfig は設定ファイル(YAML)と環境変数({EnvPrefix}_API_*)を読み込み、 Config を返す。設定ファイルが存在しない場合はデフォルト値で構築する。

type HealthOutput

type HealthOutput struct {
	Body struct {
		Status string `json:"status" example:"ok" doc:"サーバーの稼働状態"`
	}
}

HealthOutput はヘルスチェックのレスポンスを表す。

type LoadConfigOptions

type LoadConfigOptions struct {
	// ConfigName はファイル名(拡張子なし)。デフォルトは "default"。
	ConfigName string
	// ConfigType はファイル形式。デフォルトは "yaml"。
	ConfigType string
	// ConfigPaths は設定ファイルの探索パス。デフォルトは ["./configs", "."]。
	ConfigPaths []string
	// EnvPrefix は環境変数のプレフィックス。デフォルトは "LOKI"。
	EnvPrefix string
}

LoadConfigOptions は LoadConfig の挙動をカスタマイズするためのオプション。

type LoggingConfig

type LoggingConfig struct {
	Level string // debug/info/warn/error
}

LoggingConfig はロギングミドルウェアの設定を表す。

type RateLimitConfig

type RateLimitConfig struct {
	RequestsPerMinute int
	Burst             int
}

RateLimitConfig はレートリミットミドルウェアの設定を表す。

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server はAPIサーバーを表す。

func NewServer

func NewServer(cfg Config) *Server

NewServer は新しいAPIサーバーを生成する。

func (*Server) API

func (s *Server) API() huma.API

API はHuma APIインスタンスを返す。

func (*Server) Shutdown

func (s *Server) Shutdown(ctx context.Context) error

Shutdown はサーバーをGracefulに停止する。 レートリミッタの内部 goroutine もここで停止する。

func (*Server) Start

func (s *Server) Start() error

Start はサーバーを起動する。

Directories

Path Synopsis
Package middleware はAPIサーバー用のChi互換ミドルウェアを提供する。
Package middleware はAPIサーバー用のChi互換ミドルウェアを提供する。

Jump to

Keyboard shortcuts

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