common

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Mar 7, 2021 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	PathPing                  = "/ping"
	PathSend                  = "/send"
	PathConnect               = "/connect"
	PathClaim                 = "/claim"
	PathInfo                  = "/info"
	PathDisconnect            = "/disconnect"
	PathChannelSubscribe      = "/channel/subscribe/:channel"
	PathChannelUnsubscribe    = "/channel/unsubscribe/:channel"
	PathReceiveMessage        = "/_/message"
	PathReceiveChannelMessage = "/_/message/channel"
)
View Source
const (
	ErrorUserIdRequired        = "USER_ID_REQUIRED"
	ErrorInvalidExpiration     = "INVALID_EXPIRATION"
	ErrorNegativeExpiration    = "NEGATIVE_EXPIRATION"
	ErrorInvalidDuration       = "INVALID_DURATION"
	ErrorNegativeDuration      = "NEGATIVE_DURATION"
	ErrorGettingConnection     = "ERROR_GETTING_CONNECTION"
	ErrorGettingUser           = "ERROR_GETTING_USER"
	ErrorGettingChannel        = "ERROR_GETTING_CHANNEL"
	ErrorTarget                = "MISSING_TARGET"
	ErrorInvalidAuthorization  = "INVALID_AUTHORIZATION"
	ErrorMissingAuthentication = "MISSING_AUTHENTICATION"
	ErrorInvalidJwt            = "INVALID_JWT"
	ErrorClaimIdAlreadyUsed    = "CLAIM_ID_ALREADY_USED"
	ErrorCheckingClaim         = "ERROR_CHECKING_CLAIM"
	ErrorGettingClaim          = "ERROR_GETTING_CLAIM"
	ErrorMissingClaim          = "MISSING_CLAIM"
	ErrorExpiredClaim          = "EXPIRED_CLAIM"
	ErrorReadingMessage        = "ERROR_READING_MESSAGE"
	ErrorMarshallingMessage    = "ERROR_MARSHALLING_MESSAGE"
	ErrorInvalidMessageType    = "INVALID_MESSAGE_TYPE"
	ErrorBindingQueryParams    = "ERROR_BINDING_QUERY_PARAMS"
	ErrorGettingWorker         = "ERROR_GETTING_WORKER"
	ErrorReachingWorker        = "ERROR_REACHING_WORKER"
	ErrorDeliveringMessage     = "ERROR_DELIVERING_MESSAGING"
	ErrorInvalidContentType    = "INVALID_CONTENT_TYPE"
	ErrorReadingBody           = "ERROR_READING_BODY"
)
View Source
const MessageMethodDirect = "direct"
View Source
const MessageMethodRedis = "redis"
View Source
const ProtobufContentType = "application/protobuf"

Variables

View Source
var DSockVersion = "v0.4.1"
View Source
var ErrorMessages = map[string]string{
	ErrorUserIdRequired:        "User ID is required",
	ErrorInvalidExpiration:     "Error parsing expiration (must be a integer)",
	ErrorNegativeExpiration:    "Can not use 0 or negative expiration",
	ErrorInvalidDuration:       "Could not parse duration (must be a integer)",
	ErrorNegativeDuration:      "Can not use 0 or negative duration",
	ErrorGettingConnection:     "Error getting connection",
	ErrorGettingUser:           "Error getting user",
	ErrorGettingChannel:        "Error getting channel",
	ErrorTarget:                "Missing target",
	ErrorInvalidAuthorization:  "Invalid authorization",
	ErrorMissingAuthentication: "Did not provide an authentication method",
	ErrorInvalidJwt:            "Could not validate JWT",
	ErrorClaimIdAlreadyUsed:    "Claim ID is already used",
	ErrorCheckingClaim:         "Error checking if claim already exists",
	ErrorGettingClaim:          "Error getting claim",
	ErrorMissingClaim:          "Could not find claim",
	ErrorExpiredClaim:          "Claim has expired",
	ErrorReadingMessage:        "Error reading message",
	ErrorMarshallingMessage:    "Error marshalling message",
	ErrorInvalidMessageType:    "Invalid message type, must be text or binary",
	ErrorBindingQueryParams:    "Error binding query parameters",
	ErrorGettingWorker:         "Error getting worker",
	ErrorReachingWorker:        "Error reaching worker",
	ErrorDeliveringMessage:     "Error delivering message",
	ErrorInvalidContentType:    "Invalid Content-Type",
	ErrorReadingBody:           "Error reading body",
}
View Source
var RequestIdMiddleware = requestid.New(requestid.Config{
	Generator: func() string {
		return uuid.New().String()
	},
})

Functions

func GetLocalIP added in v0.4.0

func GetLocalIP() string

func IncludesString added in v0.3.0

func IncludesString(texts []string, text string) bool

func NewGinEngine added in v0.3.1

func NewGinEngine(logger *zap.Logger, options *DSockOptions) *gin.Engine

func PingHandler added in v0.3.3

func PingHandler(c *gin.Context)

func RandomString

func RandomString(length int) string

func RemoveEmpty added in v0.1.2

func RemoveEmpty(texts []string) []string

func RemoveString

func RemoveString(texts []string, text string) []string

func SetupConfig

func SetupConfig() error

func TokenMiddleware

func TokenMiddleware(token string) gin.HandlerFunc

/ Validates that token matches from query parameter or from Authorization header

func UniqueString

func UniqueString(texts []string) []string

Types

type ApiError added in v0.1.2

type ApiError struct {
	/// Wrapped error. Can be nil if application/validation error
	InternalError error
	/// Error code. Used to take error message from ErrorMessages
	ErrorCode string
	/// If set, overrides error message from ErrorCode
	CustomErrorMessage string
	/// HTTP status code
	StatusCode int
	/// Request ID
	RequestId string
}

func (*ApiError) Error added in v0.1.2

func (apiError *ApiError) Error() string

func (*ApiError) Format added in v0.2.0

func (apiError *ApiError) Format() (int, gin.H)

func (*ApiError) Send added in v0.1.2

func (apiError *ApiError) Send(c *gin.Context)

type DSockOptions

type DSockOptions struct {
	RedisOptions *redis.Options
	Address      string
	Port         int
	QuitChannel  chan struct{}
	Debug        bool
	LogRequests  bool
	/// Token for your API -> dSock and between dSock services
	Token string
	/// JWT parsing/verifying options
	Jwt JwtOptions
	/// Default channels to subscribe on join
	DefaultChannels []string
	/// The message method between the API to the worker
	MessagingMethod string
	/// The worker hostname
	DirectHostname string
	/// The worker port
	DirectPort int
}

func GetOptions

func GetOptions(worker bool) (*DSockOptions, error)

type JwtOptions

type JwtOptions struct {
	JwtSecret string
}

type ResolveOptions added in v0.1.2

type ResolveOptions struct {
	Connection string `form:"id"`
	User       string `form:"user"`
	Session    string `form:"session"`
	Channel    string `form:"channel"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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