core

package
v0.0.0-...-e6d8c27 Latest Latest
Warning

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

Go to latest
Published: Mar 14, 2024 License: MIT Imports: 25 Imported by: 0

Documentation

Index

Constants

View Source
const CONTINUE = true
View Source
const FINISHED = false

Variables

View Source
var AUTH_PATH = gin_ninsho.NinshoGinPath{
	Unauthorized: "/auth/login",
	Callback:     "/auth/callback",
	AfterAuth:    "/_torima/back",
}
View Source
var AfterLogDirector = MakeLogDirector("after")
View Source
var BeforeLogDirector = MakeLogDirector("before")
View Source
var CLIENT_ID = readEnvOrPanic("TORIMA_CLIENT_ID")
View Source
var CLIENT_SECRET = readEnvOrPanic("TORIMA_CLIENT_SECRET")
View Source
var CONFIG_FILE = "./config.yaml"
View Source
var DB_CONFIG = readEnv("TORIMA_DB_CONFIG", "file:./data/db.sqlite3?_fk=1")
View Source
var DB_TYPE = readEnv("TORIMA_DB_TYPE", "sqlite3")

configuration of DB

other

View Source
var DEFAULT_PROXYWEB_PAGES = []TorimaProxyWebPage{
	ConfigWeb,
	StaticWeb,
	LoginWebs,
}
View Source
var SECRET = readEnv("TORIMA_SECRET", randomString(32))
View Source
var STATIC_FOLDER = "./static"

Functions

func AuthDirector

func AuthDirector(proxy *TorimaProxy, req *http.Request, c *gin.Context) (bool, error)

func ConfigWeb

func ConfigWeb(proxy *TorimaProxy, r *gin.RouterGroup)

func DefaultRouteDirector

func DefaultRouteDirector(proxy *TorimaProxy, req *http.Request, c *gin.Context) (bool, error)

func InjectHTMLModifyResponse

func InjectHTMLModifyResponse(html string, proxy *TorimaProxy, res *http.Response, c *gin.Context) (bool, error)

func InjectServiceWorkerModifyResponse

func InjectServiceWorkerModifyResponse(proxy *TorimaProxy, res *http.Response, c *gin.Context) (bool, error)

func LogReq

func LogReq(req *http.Request)

*

  • LogReq is the function that logs the request.

*

func LoginWebs

func LoginWebs(proxy *TorimaProxy, r *gin.RouterGroup)

func MainModifyResponse

func MainModifyResponse(proxy *TorimaProxy, res *http.Response)

func RouteDirector

func RouteDirector(host string, proxy *TorimaProxy, req *http.Request, c *gin.Context) (bool, error)

func SanitizeHeaderDirector

func SanitizeHeaderDirector(proxy *TorimaProxy, req *http.Request, c *gin.Context) (bool, error)

func StaticWeb

func StaticWeb(proxy *TorimaProxy, r *gin.RouterGroup)

func ThirdPartyDirector

func ThirdPartyDirector(proxy *TorimaProxy, req *http.Request, c *gin.Context) (bool, error)

Types

type Database

type Database struct {
	Ctx    context.Context
	Client *ent.Client
}

func InitDB

func InitDB(path string) (*Database, error)

func (*Database) CreateRequestLog

func (db *Database) CreateRequestLog(header string, body []byte, flag string) *ent.RequestLogCreate

type FlowLog

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

type FlowLogger

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

func NewFlowLogger

func NewFlowLogger() FlowLogger

func (*FlowLogger) Add

func (logger *FlowLogger) Add(f any, result bool)

func (*FlowLogger) Show

func (flowLogs *FlowLogger) Show()

type TorimaConfig

type TorimaConfig struct {
	DefaultOrigin   string   `yaml:"default_origin" default:"127.0.0.1:5000"`
	Host            string   `yaml:"host" default:"http://127.0.0.1:8080"`
	Port            int      `yaml:"port" default:"8080" `
	Scheme          string   `yaml:"scheme" default:"http"`
	WhiteListPath   []string `yaml:"white_list_path" default:"[]"`
	ProtectionScope []string `yaml:"protection_scope" default:"[]"`
	WebRoot         string   `yaml:"web_root" default:"/torima"`
}

type TorimaDirector

type TorimaDirector = func(proxy *TorimaProxy, req *http.Request, c *gin.Context) (bool, error)

func MakeLogDirector

func MakeLogDirector(flag string) TorimaDirector

type TorimaModifyResponse

type TorimaModifyResponse = func(proxy *TorimaProxy, req *http.Response, c *gin.Context) (bool, error)

type TorimaPackageArgument

type TorimaPackageArgument interface{ *http.Request | *http.Response }

type TorimaProxy

type TorimaProxy struct {
	Directors       []TorimaDirector
	ModifyResponses []TorimaModifyResponse
	ProxyWebPages   []TorimaProxyWebPage
	Engine          *gin.Engine
	Database        *Database
	ErrorHandler    *gin.HandlerFunc
	Config          *TorimaConfig
	RequestCount    int
}

func NewOchancoProxy

func NewOchancoProxy(
	r *gin.Engine,
	directors []TorimaDirector,
	modifyResponses []TorimaModifyResponse,
	proxyWebPages []TorimaProxyWebPage,
	config *TorimaConfig,
	database *Database,
) TorimaProxy

func ProxyServer

func ProxyServer() (*TorimaProxy, error)

func (*TorimaProxy) Director

func (proxy *TorimaProxy) Director(req *http.Request, c *gin.Context)

*

  • Directors is a list of functions that modify the
  • request before it is sent to the target server. *

func (*TorimaProxy) ModifyResponse

func (proxy *TorimaProxy) ModifyResponse(res *http.Response, c *gin.Context) error

*

  • ModifyResponses is a list of functions that modify the
  • response before it is sent to the client.

*

type TorimaProxyWebPage

type TorimaProxyWebPage = func(proxy *TorimaProxy, c *gin.RouterGroup)

Jump to

Keyboard shortcuts

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