services

package
v0.0.0-...-fa0cbd2 Latest Latest
Warning

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

Go to latest
Published: Jan 20, 2025 License: MIT Imports: 36 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ClickhouseDSNFlag = "clickhouse-dsn"
)

Variables

This section is empty.

Functions

func RegisterAPIFlags

func RegisterAPIFlags(flags []cli.Flag) []cli.Flag

func RegisterClickHouseDBFlags

func RegisterClickHouseDBFlags(f []cli.Flag) []cli.Flag

func RegisterClickHouseFlags

func RegisterClickHouseFlags(f []cli.Flag) []cli.Flag

func RegisterCommonFlags

func RegisterCommonFlags(f []cli.Flag) []cli.Flag

func RegisterEndpointsFlags

func RegisterEndpointsFlags(f []cli.Flag) []cli.Flag

func RegisterServicesConfigFlags

func RegisterServicesConfigFlags(flags []cli.Flag) []cli.Flag

func RegisterWebFlags

func RegisterWebFlags(f []cli.Flag) []cli.Flag

Types

type AccessHistory

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

func NewAccessHistory

func NewAccessHistory() *AccessHistory

func (*AccessHistory) Store

func (s *AccessHistory) Store(oip string, oua string, nip string, nua string) (bool, int)

type Bucket

type Bucket struct {
}

func NewBucket

func NewBucket() *Bucket

func (*Bucket) Get

func (s *Bucket) Get(mc jwt.MapClaims) (*ratelimit.Bucket, error)

type Claims

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

func NewClaims

func NewClaims(c *cli.Context) *Claims

func (*Claims) Get

func (s *Claims) Get(tokenString string, apiKey string) (jwt.MapClaims, error)

type ClickHouse

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

func NewClickHouse

func NewClickHouse(c *cli.Context, db DBProvider) *ClickHouse

func (*ClickHouse) Add

func (s *ClickHouse) Add(sr *StatRecord) error

func (*ClickHouse) Close

func (s *ClickHouse) Close()

type ClickHouseDB

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

func NewClickHouseDB

func NewClickHouseDB(c *cli.Context) *ClickHouseDB

func (*ClickHouseDB) Close

func (s *ClickHouseDB) Close()

func (*ClickHouseDB) Get

func (s *ClickHouseDB) Get() (*sql.DB, error)

type DBProvider

type DBProvider interface {
	Get() (*sql.DB, error)
}

type Distribution

type Distribution string
const (
	Hash     Distribution = "Hash"
	NodeHash Distribution = "NodeHash"
)

type EndpointsProvider

type EndpointsProvider string
const (
	Kubernetes  EndpointsProvider = "Kubernetes"
	Environment EndpointsProvider = "Environment"
)

type HTTPProxy

type HTTPProxy struct {
	lazymap.LazyMap[*httputil.ReverseProxy]
	// contains filtered or unexported fields
}

func NewHTTPProxy

func NewHTTPProxy(r *Resolver) *HTTPProxy

func (*HTTPProxy) Get

func (s *HTTPProxy) Get(ctx context.Context, src *Source, logger *logrus.Entry) (*httputil.ReverseProxy, error)

type K8SClient

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

func NewK8SClient

func NewK8SClient() *K8SClient

func (*K8SClient) Get

func (s *K8SClient) Get() (*kubernetes.Clientset, error)

type K8SEndpoints

type K8SEndpoints struct {
	lazymap.LazyMap[*corev1.Endpoints]
	// contains filtered or unexported fields
}

func NewEndpoints

func NewEndpoints(c *cli.Context, cl *K8SClient) *K8SEndpoints

func (*K8SEndpoints) Get

func (s *K8SEndpoints) Get(ctx context.Context, name string) (*corev1.Endpoints, error)

type Location

type Location struct {
	Ports
	IP          net.IP
	Unavailable bool
}

type Mod

type Mod struct {
	Type  string `json:"type"`
	Path  string `json:"path"`
	Extra string `json:"extra"`
	Name  string `json:"name"`
}

Mod struct represents modification of source file.

type Ports

type Ports struct {
	HTTP  int
	Probe int
}

type Resolver

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

func NewResolver

func NewResolver(cfg *ServicesConfig, svcLoc *ServiceLocation) *Resolver

func (*Resolver) Resolve

func (s *Resolver) Resolve(ctx context.Context, src *Source, logger *logrus.Entry) (*Location, error)

type ResponseWriterInterceptor

type ResponseWriterInterceptor struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

func NewResponseWrtierInterceptor

func NewResponseWrtierInterceptor(w http.ResponseWriter) *ResponseWriterInterceptor

func (*ResponseWriterInterceptor) Flush

func (w *ResponseWriterInterceptor) Flush()

func (*ResponseWriterInterceptor) GroupedStatusCode

func (w *ResponseWriterInterceptor) GroupedStatusCode() int

func (*ResponseWriterInterceptor) Hijack

func (*ResponseWriterInterceptor) Write

func (w *ResponseWriterInterceptor) Write(p []byte) (int, error)

func (*ResponseWriterInterceptor) WriteHeader

func (w *ResponseWriterInterceptor) WriteHeader(statusCode int)

type ServiceConfig

type ServiceConfig struct {
	Name              string            `yaml:"name"`
	Distribution      Distribution      `yaml:"distribution"`
	EndpointsProvider EndpointsProvider `yaml:"endpointsProvider"`
	PreferLocalNode   bool              `yaml:"preferLocalNode"`
	Headers           map[string]string `yaml:"headers"`
}

type ServiceLocation

type ServiceLocation struct {
	lazymap.LazyMap[*Location]
	// contains filtered or unexported fields
}

func NewServiceLocationPool

func NewServiceLocationPool(c *cli.Context, ep *K8SEndpoints) *ServiceLocation

func (*ServiceLocation) Get

func (s *ServiceLocation) Get(ctx context.Context, cfg *ServiceConfig, src *Source) (*Location, error)

type ServicesConfig

type ServicesConfig map[string]*ServiceConfig

func LoadServicesConfigFromYAML

func LoadServicesConfigFromYAML(c *cli.Context) (*ServicesConfig, error)

func (ServicesConfig) GetDefault

func (s ServicesConfig) GetDefault() *ServiceConfig

func (ServicesConfig) GetMod

func (s ServicesConfig) GetMod(name string) *ServiceConfig

func (ServicesConfig) GetMods

func (s ServicesConfig) GetMods() []string

type Source

type Source struct {
	Type       string `json:"type"`
	Name       string `json:"name"`
	InfoHash   string `json:"info_hash"`
	Path       string `json:"path"`
	OriginPath string `json:"origin_path"`
	Token      string `json:"token"`
	ApiKey     string `json:"api_key"`
	Query      string `json:"query"`
	Mod        *Mod
}

Source struct represents torrent file source. Source may have additional modification.

func (*Source) GetEdgeName

func (s *Source) GetEdgeName() string

func (*Source) GetEdgeType

func (s *Source) GetEdgeType() string

func (*Source) GetKey

func (s *Source) GetKey() string

type SourceType

type SourceType string
const (
	Internal SourceType = "internal"
	External SourceType = "external"
)

type StandardClaims

type StandardClaims struct {
	Grace  int    `json:"grace"`
	Preset string `json:"preset"`
	Rate   string `json:"rate"`
	Role   string `json:"role"`
	jwt.StandardClaims
}

type StatRecord

type StatRecord struct {
	Timestamp     time.Time
	ApiKey        string
	BytesWritten  uint64
	TTFB          uint64
	Duration      uint64
	Path          string
	InfoHash      string
	OriginalPath  string
	SessionID     string
	Domain        string
	Status        uint64
	GroupedStatus uint64
	Edge          string
	Source        string
	Role          string
	Ads           bool
}

type ThrottledResponseWriter

type ThrottledResponseWriter struct {
	http.ResponseWriter
	// contains filtered or unexported fields
}

func (*ThrottledResponseWriter) Flush

func (w *ThrottledResponseWriter) Flush()

func (*ThrottledResponseWriter) Hijack

func (*ThrottledResponseWriter) Write

func (w *ThrottledResponseWriter) Write(p []byte) (int, error)

func (*ThrottledResponseWriter) WriteHeader

func (w *ThrottledResponseWriter) WriteHeader(statusCode int)

type URLParser

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

func NewURLParser

func NewURLParser(c *ServicesConfig) *URLParser

func (*URLParser) Parse

func (s *URLParser) Parse(url *url.URL) (*Source, error)

Parse extracts information about source and additional modifiacation of it

type Web

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

func NewWeb

func NewWeb(c *cli.Context, parser *URLParser, r *Resolver, pr *HTTPProxy, claims *Claims, bp *Bucket, ch *ClickHouse, cfg *ServicesConfig, ah *AccessHistory) *Web

func (*Web) Close

func (s *Web) Close()

func (*Web) Serve

func (s *Web) Serve() error

Jump to

Keyboard shortcuts

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