common

package
v0.44.9 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2024 License: MIT Imports: 18 Imported by: 0

Documentation

Overview

Common functions, constants, and structures package for the frontend.

Index

Constants

View Source
const (
	// Toast types.
	TTYPE_ERR     = "error"
	TTYPE_INFO    = "info"
	TTYPE_SUCCESS = "success"
)
View Source
const (
	// Flow/Posts-related error messages.
	ERR_INVALID_REPLY      = "no valid reply content entered"
	ERR_POST_UNAUTH_DELETE = "you can delete your own posts only!"
	ERR_POST_NOT_FOUND     = "post not found"
	ERR_USER_NOT_FOUND     = "user not found"
	ERR_PRIVATE_ACC        = "this account is private"

	// Generic error messages on the FE.
	ERR_CANNOT_REACH_BE = "cannot reach the server"
	ERR_CANNOT_GET_DATA = "cannot get the data"
	ERR_LOGIN_AGAIN     = "please log-in again"

	// Login-related error messages.
	MSG_USER_ACTIVATED          = "user successfully activated, try logging in"
	ERR_ALL_FIELDS_REQUIRED     = "all fields are required"
	ERR_LOGIN_CHARS_LIMIT       = "only a-z, A-Z characters and numbers can be used"
	ERR_ACCESS_DENIED           = "wrong credentials entered"
	ERR_LOCAL_STORAGE_USER_FAIL = "cannot save user's data to the browser"
	ERR_ACTIVATION_INVALID_UUID = "invalid activation UUID"
	ERR_ACTIVATION_EXPIRED_UUID = "expired activation UUID"

	// Notification-related (non-)error messages.
	MSG_SUBSCRIPTION_UPDATED      = "subscription updated"
	MSG_UNSUBSCRIBED_SUCCESS      = "successfully unsubscribed, notifications off"
	ERR_SUBSCRIPTION_UPDATE_FAIL  = "failed to update the subscription, try again later"
	ERR_NOTIF_PERMISSION_DENIED   = "notification permission denied by user"
	ERR_NOTIF_UNSUPPORTED_BROWSER = "notifications are not supported in this browser"

	// Polls-related (non-)error messages.
	MSG_NO_POLL_TO_SHOW      = "no poll to show, click here to create one!"
	ERR_POLL_UNAUTH_DELETE   = "you can delete your own polls only!"
	ERR_POLL_OPTION_MISMATCH = "such option is not associated to the poll"

	// Post-related (non-)error messages.
	MSG_IMAGE_READY             = "image is ready for the upload"
	ERR_LOCAL_STORAGE_LOAD_FAIL = "cannot decode user's data: "
	ERR_POST_TEXTAREA_EMPTY     = "no valid content entered"
	ERR_POLL_FIELDS_REQUIRED    = "poll question and at least two options are required"
	ERR_POST_UNKNOWN_TYPE       = "unknown post type"

	// Register-related error messages.
	ERR_REGISTER_FIELDS_REQUIRED = "all fields are required"
	ERR_REGISTER_CHARSET_LIMIT   = "only a-z, A-Z characters and numbers can be used"
	ERR_WRONG_EMAIL_FORMAT       = "invalid e-mail address format entered"

	// Reset-related (non-)error messages.
	MSG_RESET_PASSPHRASE_SUCCESS = "your passphrase has been changed, check your mail inbox"
	MSG_RESET_REQUEST_SUCCESS    = "the passphrase reset request has been sent, check your mail inbox"
	ERR_RESET_FIELD_REQUIRED     = "e-mail address is required"
	ERR_RESET_UUID_FIELD_EMPTY   = "UUID string is required to continue, check your mail inbox"
	ERR_RESET_INVALID_INPUT_DATA = "invalid input data entered"

	// Settings-related (non-)error messages.
	MSG_PASSPHRASE_UPDATED       = "passphrase updated successfully"
	MSG_ABOUT_TEXT_UPDATED       = "about text updated successfully"
	MSG_WEBSITE_UPDATED          = "website updated successfully"
	MSG_SUBSCRIPTION_REQ_SUCCESS = "successfully subscribed to notifs"
	MSG_LOCAL_TIME_TOGGLE        = "local time mode toggled"
	MSG_PRIVATE_MODE_TOGGLE      = "private mode toggled"
	MSG_AVATAR_CHANGE_SUCCESS    = "avatar updated successfully"
	ERR_PASSPHRASE_MISMATCH      = "passphrases do not match"
	ERR_PASSPHRASE_MISSING       = "passphrase fields need to be filled"
	ERR_ABOUT_TEXT_UNCHANGED     = "the about textarea is empty, or the text has not changed"
	ERR_ABOUT_TEXT_CHAR_LIMIT    = "about text has to be shorter than 100 chars"
	ERR_WEBSITE_UNCHANGED        = "website URL has to be filled, or changed"
	ERR_WEBSITE_REGEXP_FAIL      = "failed to check the website format (regexp object failed)"
	ERR_WEBSITE_INVALID          = "website prolly not a valid URL"
	ERR_SUBSCRIPTION_BLANK_UUID  = "blank UUID string"
	ERR_SUBSCRIPTION_REQ_FAIL    = "failed to subscribe to notifications: "

	// Users-related (non-)error messages.
	MSG_USER_UPDATED_SUCCESS   = "user has been updated, request was removed"
	MSG_FOLLOW_REQUEST_REMOVED = "user has been updated, request was removed"
	MSG_REQ_TO_FOLLOW_SUCCESS  = "request to follow sent successfully"
	MSG_SHADE_SUCCESSFUL       = "user (un)shaded successfully"
)

Variables

View Source
var (
	// those vars are used during the build --- linker (ld) bakes the values in
	AppVersion     string
	AppPepper      string
	VapidPublicKey string
)
View Source
var Client = sse.Client{
	HTTPClient: &http.Client{
		Timeout: 15 * time.Second,
	},
	OnRetry: func(err error, duration time.Duration) {
		fmt.Printf("conn error: %v\n", err)
		time.Sleep(duration)
	},
	ResponseValidator: DefaultValidator,
	Backoff: sse.Backoff{
		InitialInterval: 500 * time.Millisecond,
		Multiplier:      float64(1.5),

		Jitter:         float64(0.5),
		MaxInterval:    30 * time.Second,
		MaxElapsedTime: 45 * time.Second,
		MaxRetries:     30,
	},
}

Custom HTTP client.

View Source
var DefaultValidator sse.ResponseValidator = func(r *http.Response) error {
	if r.StatusCode != http.StatusOK {
		return fmt.Errorf("expected status code %d %s, received %d %s", http.StatusOK, http.StatusText(http.StatusOK), r.StatusCode, http.StatusText(r.StatusCode))
	}
	cts := r.Header.Get("Content-Type")

	if expected := "text/event-stream"; cts != expected {
		return fmt.Errorf("expected content type to have %q, received %q", expected, cts)
	}
	return nil
}

Default response validator. https://pkg.go.dev/github.com/tmaxmax/go-sse@v0.8.0#ResponseValidator

View Source
var NoopValidator sse.ResponseValidator = func(_ *http.Response) error {
	return nil
}

Noop response validator. https://pkg.go.dev/github.com/tmaxmax/go-sse@v0.8.0#ResponseValidator

View Source
var URL = func() string {

	if os.Getenv("APP_URL_MAIN") != "" {
		return "https://" + os.Getenv("APP_URL_MAIN")
	}

	return "http://localhost:8080"
}()

Functions

func FetchData added in v0.42.0

func FetchData(input *CallInput, output *Response) bool

ng-func

func LoadUser added in v0.41.8

func LoadUser(encoded string, user *models.User) error

func ReadFile added in v0.41.2

func ReadFile(file app.Value) (data []byte, err error)

func SSEClient added in v0.44.9

func SSEClient()

func SaveUser added in v0.41.8

func SaveUser(plain *string, user *models.User) error

Types

type CallInput

type CallInput struct {
	Method      string
	Url         string
	CallerID    string
	PageNo      int
	HideReplies bool

	// payload body for the API call
	Data interface{}
}

DTO-in structure for the API call.

type Response added in v0.42.0

type Response struct {
	Code      int
	Message   string      `json:"message"`
	Timestamp int64       `json:"timestamp"`
	Data      interface{} `json:"data"`
}

standardized common response from API

type Toast added in v0.41.1

type Toast struct {
	AppContext *app.Context
	TLink      string
	TText      string
	TType      string
	TID        int64
}

func (*Toast) Context added in v0.41.1

func (t *Toast) Context(ctx *app.Context) *Toast

func (*Toast) Dispatch added in v0.41.1

func (t *Toast) Dispatch(c interface{}, f func(*Toast, interface{}))
func (t *Toast) Link(link string) *Toast

func (*Toast) Text added in v0.41.1

func (t *Toast) Text(text string) *Toast

func (*Toast) Type added in v0.41.1

func (t *Toast) Type(typ string) *Toast

type ToastInterface added in v0.41.1

type ToastInterface interface {
	Context(*app.Context) *Toast
	Text(string) *Toast
	Link(string) *Toast
	Type(string) *Toast
	Dispatch(interface{}, func(*Toast, interface{}))
}

Jump to

Keyboard shortcuts

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