pgparse

package module
v0.0.0-...-a7829b0 Latest Latest
Warning

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

Go to latest
Published: Jul 27, 2026 License: MIT Imports: 11 Imported by: 2

README

pgparse

pgparse is Part of pgrtools. See main site for license/warranty.

pgparse is designed to help with commonly needed parsing tools for web, api, json, etc.

Functions

Last10

Used commonly for VoIP and RTC operations, this function returns the last 10 characters of a string. If less than 10 digits, the string is returned.

Last10 Example
newstring := pgparse.Last10("12345678910");

newstring would be: 2345678910

CheckFields

Checks to see if required fields are within a map[string]string.

CheckFields Example
requiredfields := []string{"email"}
_, err = pgparse.CheckFields(keyVal, requiredfields)
if err != nil {
    log.Println(connectingip, "[getRecoverKey] parse error", err.Error())
    http.Redirect(w, r, "https://...", http.StatusMovedPermanently)
    return
}
GetUUID

Returns a UUID value as a string

GetUUID Example
myUUID := pgparse.GetUUID()
LowerKeys

Transforms the keys from a map[sting]string to lower case.

LowerKeys Example
bodyVal := make(amp[string]string)
\\ make your bodyVal...

\\ change bodyVal keys to lower case
bodyVal = pgparse.LowerKeys(bodyval)
ParseBody

Parses an r.body []byte and makes a map[string]string of the Json or QueryString objects.

ParseBody Example
body, err := ioutil.ReadAll(r.Body)
if err != nil {
    ...
}

keyVal := pgparse.ParseBody(body)
ParseBodyErr

Takes an r.body []byte and returns a map[string]string, error of the json or query strings.

ParseBodyErr Example
body, err := ioutil.ReadAll(r.Body)
if err != nil {
    ...
}

keyVal, err := pgparse.ParseBodyErr(body)
ParseBodyFields

Receives a r http.Request and required fields []string. Returns a map[string]string, error.

ParseBodyFields Example
requiredfields := []string{"email", "name", "age"}
keyVal, err := pgparse.ParseBodyFields(r, requiredfields)
PgParseForm

Receives a r http.Request and parses all form fields. Returns a map[string]string, error.

PgParseForm Example
keyVal, err := pgparse.PgParseForm(r)
PgParseFormFields

Receives a r http.Request and required fields []string. Parses all form fields and checks for required fields. Returns a map[string]string, error.

PgParseFormFields Example
requiredfields := []string{"email", "name", "age"}
keyVal, err := pgparse.PgParseFormFields(r, requiredfields)

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CheckFields

func CheckFields(mapstring map[string]string, reqfields []string) (bool, error)

func CheckFieldsAny

func CheckFieldsAny(mapstring map[string]any, reqfields []string) (bool, error)

func CheckHoneypot

func CheckHoneypot(mapstring map[string]string, honeypot string) bool

func CheckTurnstile

func CheckTurnstile(mapstring map[string]string, secret string, remoteip string) (bool, error)

func GetUUID

func GetUUID() string

func Last10

func Last10(val string) string

func LowerKeys

func LowerKeys(keyVal map[string]string) map[string]string

func ParseBody

func ParseBody(body []byte) map[string]string

func ParseBodyErr

func ParseBodyErr(body []byte) (map[string]string, error)

func ParseBodyErrAny

func ParseBodyErrAny(body []byte) (map[string]any, error)

func ParseBodyFields

func ParseBodyFields(r *http.Request, reqfields []string) (map[string]string, error)

func ParseBodyFieldsAny

func ParseBodyFieldsAny(r *http.Request, reqfields []string) (map[string]any, error)

func PgParseForm

func PgParseForm(r *http.Request) (map[string]string, error)

func PgParseFormFields

func PgParseFormFields(r *http.Request, reqfields []string) (map[string]string, error)

Types

type SendTurnstile

type SendTurnstile struct {
	Secret   string `json:"secret"`
	Token    string `json:"response"`
	RemoteIp string `json:"remoteip"`
	Uuid     string `json:"idempotency_key"`
}

Jump to

Keyboard shortcuts

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