google

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Jun 24, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package google provides integrations with Google services: OAuth2 token handling and reCAPTCHA verification.

Index

Constants

View Source
const (
	ErrCodeCaptchaNotSupportedVer = "CPT-001"
	ErrCodeCaptchaRequest         = "CPT-002"
	ErrCodeCaptchaResponseFormat  = "CPT-003"
	ErrCodeCaptchaResponseStatus  = "CPT-004"
)
View Source
const (
	ErrCodeOAuthConfigRead     = "OAUTH-001"
	ErrCodeOAuthService        = "OAUTH-002"
	ErrCodeOAuthGetUser        = "OAUTH-003"
	ErrCodeOAuthConfigFileRead = "OAUTH-004"
)

Variables

View Source
var (
	ErrCaptchaNotSupportedVer = func(ctx context.Context) error {
		return jet.NewAppErrBuilder(ErrCodeCaptchaNotSupportedVer, "not supported version").C(ctx).Business().Err()
	}
	ErrCaptchaRequest = func(ctx context.Context, err error) error {
		return jet.NewAppErrBuilder(ErrCodeCaptchaRequest, "request error").Wrap(err).C(ctx).Err()
	}
	ErrCaptchaResponseFormat = func(ctx context.Context, err error) error {
		return jet.NewAppErrBuilder(ErrCodeCaptchaResponseFormat, "response format").Wrap(err).C(ctx).Err()
	}
	ErrCaptchaResponseStatus = func(ctx context.Context, status string) error {
		return jet.NewAppErrBuilder(ErrCodeCaptchaResponseStatus, "response status: %s", status).C(ctx).Err()
	}
)
View Source
var (
	ErrOAuthConfigRead = func(ctx context.Context, cause error) error {
		return jet.NewAppErrBuilder(ErrCodeOAuthConfigRead, "reading config").Wrap(cause).C(ctx).Business().Err()
	}
	ErrOAuthService = func(ctx context.Context, cause error) error {
		return jet.NewAppErrBuilder(ErrCodeOAuthService, "service").Wrap(cause).C(ctx).Business().Err()
	}
	ErrOAuthGetUser = func(ctx context.Context, cause error) error {
		return jet.NewAppErrBuilder(ErrCodeOAuthGetUser, "get user").Wrap(cause).C(ctx).Business().Err()
	}
	ErrOAuthConfigFileRead = func(ctx context.Context, cause error) error {
		return jet.NewAppErrBuilder(ErrCodeOAuthConfigFileRead, "reading config").Wrap(cause).C(ctx).Business().Err()
	}
)

Functions

This section is empty.

Types

type Captcha

type Captcha interface {
	// Verify captcha
	Verify(ctx context.Context, rq *CaptchaRequest) (bool, error)
}

func NewCaptcha

func NewCaptcha(cfg *Config, logger jet.CLogger) Captcha

type CaptchaRequest

type CaptchaRequest struct {
	Captcha  string // Captcha - token from client to be checked
	ClientIP string // ClientIP - client real ip
	Version  string // Version - captcha version
}

type Config

type Config struct {
	ConfigurationPath string  `mapstructure:"configuration_path"`
	JsonConfiguration string  `mapstructure:"json_configuration"`
	ClientTimeout     int     `mapstructure:"client_timeout"`
	ReCaptchaSecretV2 string  `mapstructure:"recaptcha_secret_v2"`
	ReCaptchaSecretV3 string  `mapstructure:"recaptcha_secret_v3"`
	ReCaptchaScore    float64 `mapstructure:"recaptcha_score"`
}

type OAuth2

type OAuth2 interface {
	// GetGoogleUser retrieves google user info
	GetGoogleUser(ctx context.Context, token string) (*oauthv2.Userinfo, error)
}

func NewOAuth

func NewOAuth(cfg *Config, logger jet.CLogger) (OAuth2, error)

Jump to

Keyboard shortcuts

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