utils

package
v0.0.0-...-86143b1 Latest Latest
Warning

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

Go to latest
Published: Dec 4, 2025 License: GPL-3.0 Imports: 23 Imported by: 0

Documentation

Index

Constants

View Source
const (
	BaseURL = "https://baak.gunadarma.ac.id"
	BaseIP  = "103.23.40.57" // IP address for direct access
)

Variables

View Source
var (
	ErrCircuitOpen = errors.New("circuit breaker is open")
)
View Source
var (
	Limiter = rate.NewLimiter(rate.Limit(5), 10)
)

Functions

func EnsureSessionPublic

func EnsureSessionPublic() error

EnsureSessionPublic is a public wrapper around ensureSession

func FetchDocument

func FetchDocument(targetURL string) (*goquery.Document, error)

func FetchDocumentWithRetry

func FetchDocumentWithRetry(url string, referrer string, maxRetries int) (*goquery.Document, error)

Fetch a document with proper referrer and headers

func GetCSRFToken

func GetCSRFToken(url string) (string, error)

GetCSRFToken fetches a page and extracts the CSRF token from a hidden input field.

func GetCookieJar

func GetCookieJar() (http.CookieJar, error)

GetCookieJar returns a cookie jar for HTTP requests

func GetJadwal

func GetJadwal(url string) (models.Jadwal, error)

func GetKegiatan

func GetKegiatan(url string) ([]models.Kegiatan, error)

func GetKelasbaru

func GetKelasbaru(baseURL string) ([]models.KelasBaru, error)

func GetMahasiswaBaru

func GetMahasiswaBaru(url string) ([]models.MahasiswaBaru, error)

func GetTimeStampLUT

func GetTimeStampLUT() ([][]string, error)

func GetUTS

func GetUTS(url string) ([]models.UTS, error)

func IsCloudflareChallenge

func IsCloudflareChallenge(html string) bool

IsCloudflareChallenge checks if the HTML response is a Cloudflare challenge

func WriteErrorResponse

func WriteErrorResponse(w http.ResponseWriter, status int, message string)

func WriteErrorResponseWithCode

func WriteErrorResponseWithCode(w http.ResponseWriter, status int, message string, code string)

func WriteHTTPError

func WriteHTTPError(w http.ResponseWriter, err error)

func WriteInternalServerError

func WriteInternalServerError(w http.ResponseWriter)

func WriteJSONResponse

func WriteJSONResponse(w http.ResponseWriter, data interface{})

func WriteNotFoundError

func WriteNotFoundError(w http.ResponseWriter)

func WriteValidationError

func WriteValidationError(w http.ResponseWriter, message string)

Types

type Cache

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

Cache is a simple in-memory cache with TTL

func GetCache

func GetCache() *Cache

GetCache returns the singleton cache instance

func (*Cache) Clear

func (c *Cache) Clear()

Clear removes all items from the cache

func (*Cache) Delete

func (c *Cache) Delete(key string)

Delete removes a value from the cache

func (*Cache) Get

func (c *Cache) Get(key string) (interface{}, bool)

Get retrieves a value from the cache

func (*Cache) Set

func (c *Cache) Set(key string, value interface{}, ttl time.Duration)

Set stores a value in the cache with TTL

func (*Cache) Stats

func (c *Cache) Stats() CacheStats

Stats returns cache statistics

type CacheItem

type CacheItem struct {
	Value      interface{}
	Expiration time.Time
}

CacheItem represents a cached item with expiration

type CacheStats

type CacheStats struct {
	TotalItems   int `json:"total_items"`
	ValidItems   int `json:"valid_items"`
	ExpiredItems int `json:"expired_items"`
}

CacheStats holds cache statistics

type CircuitBreaker

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

CircuitBreaker implements the circuit breaker pattern

func GetCircuitBreaker

func GetCircuitBreaker() *CircuitBreaker

GetCircuitBreaker returns the singleton circuit breaker

func (*CircuitBreaker) Allow

func (cb *CircuitBreaker) Allow() error

Allow checks if a request is allowed through

func (*CircuitBreaker) RecordFailure

func (cb *CircuitBreaker) RecordFailure()

RecordFailure records a failed request

func (*CircuitBreaker) RecordSuccess

func (cb *CircuitBreaker) RecordSuccess()

RecordSuccess records a successful request

func (*CircuitBreaker) Reset

func (cb *CircuitBreaker) Reset()

Reset resets the circuit breaker to closed state

func (*CircuitBreaker) State

func (cb *CircuitBreaker) State() CircuitState

State returns the current circuit breaker state

func (*CircuitBreaker) Stats

func (cb *CircuitBreaker) Stats() CircuitBreakerStats

Stats returns circuit breaker statistics

type CircuitBreakerStats

type CircuitBreakerStats struct {
	State           string    `json:"state"`
	Failures        int       `json:"failures"`
	Successes       int       `json:"successes"`
	LastFailureTime time.Time `json:"last_failure_time,omitempty"`
}

CircuitBreakerStats holds circuit breaker statistics

type CircuitState

type CircuitState int

CircuitState represents the state of the circuit breaker

const (
	CircuitClosed CircuitState = iota
	CircuitOpen
	CircuitHalfOpen
)

func (CircuitState) String

func (s CircuitState) String() string

type FlareCookie

type FlareCookie struct {
	Name     string `json:"name"`
	Value    string `json:"value"`
	Domain   string `json:"domain"`
	Path     string `json:"path"`
	Expires  int64  `json:"expires"`
	HttpOnly bool   `json:"httpOnly"`
	Secure   bool   `json:"secure"`
}

FlareCookie represents a cookie from FlareSolverr

type FlareSolverr

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

FlareSolverr handles requests through FlareSolverr proxy

func GetFlareSolverr

func GetFlareSolverr() *FlareSolverr

GetFlareSolverr returns the FlareSolverr instance if configured

func (*FlareSolverr) CheckHealth

func (fs *FlareSolverr) CheckHealth() error

CheckHealth checks if FlareSolverr is reachable and working

func (*FlareSolverr) Fetch

func (fs *FlareSolverr) Fetch(targetURL string) (string, error)

Fetch fetches a URL through FlareSolverr

func (*FlareSolverr) IsConfigured

func (fs *FlareSolverr) IsConfigured() bool

IsConfigured returns true if FlareSolverr is configured

type FlareSolverrRequest

type FlareSolverrRequest struct {
	Cmd        string `json:"cmd"`
	URL        string `json:"url"`
	MaxTimeout int    `json:"maxTimeout"`
}

FlareSolverrRequest represents a request to FlareSolverr

type FlareSolverrResponse

type FlareSolverrResponse struct {
	Status   string `json:"status"`
	Message  string `json:"message"`
	Solution struct {
		URL       string            `json:"url"`
		Status    int               `json:"status"`
		Headers   map[string]string `json:"headers"`
		Response  string            `json:"response"`
		Cookies   []FlareCookie     `json:"cookies"`
		UserAgent string            `json:"userAgent"`
	} `json:"solution"`
}

FlareSolverrResponse represents a response from FlareSolverr

type ProxyManager

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

ProxyManager handles proxy rotation for HTTP requests

func GetProxyManager

func GetProxyManager() *ProxyManager

GetProxyManager returns the singleton proxy manager

func (*ProxyManager) AddProxy

func (pm *ProxyManager) AddProxy(proxy *url.URL)

AddProxy adds a proxy to the manager

func (*ProxyManager) GetClient

func (pm *ProxyManager) GetClient() (*http.Client, error)

GetClient returns an http.Client with a proxy-enabled transport

func (*ProxyManager) GetTransport

func (pm *ProxyManager) GetTransport() *http.Transport

GetTransport returns an http.Transport with the next proxy

func (*ProxyManager) HasProxies

func (pm *ProxyManager) HasProxies() bool

HasProxies returns true if proxies are configured

type Response

type Response struct {
	Success bool        `json:"success"`
	Data    interface{} `json:"data,omitempty"`
	Error   string      `json:"error,omitempty"`
	Code    string      `json:"code,omitempty"`
}

Jump to

Keyboard shortcuts

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