util

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Sep 17, 2025 License: Apache-2.0 Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func RequestIPAddress

func RequestIPAddress(request *http.Request) string

RequestIPAddress returns the IP address of the request. It checks for the X-Forwarded-For header and falls back to the RemoteAddr.

Parameters:

  • request: The HTTP request.

Returns:

  • string: The IP address of the request.

Types

type RequestData

type RequestData struct {
	URLParameters map[string]any
	Headers       map[string]string
	Cookies       []http.Cookie
	Body          map[string]any
}

RequestData represents request data.

func NewRequestData

func NewRequestData() *RequestData

NewRequestData returns a new instance of RequestData.

func ParseInput

func ParseInput(method string, input any) (*RequestData, error)

ParseInput parses the input struct and returns the parsed data. It will populate the URL parameters, headers, cookies, and body based on the struct tags. E.g. the struct field `source: url` will be placed in the URL. It will return an error if the input is not a struct or a pointer to a struct. If the input is nil, it will return a new empty RequestData object.

Example:

type MyInput struct {
    ID   int    `json:"id" source:"url"`
    Name string `json:"name"`
}
input := &MyInput{ID: 42, Name: "example"}
data, err := ParseInput("GET", input)

Parameters:

  • method: The HTTP method for the request.
  • input: The input struct or pointer to a struct to parse.

Returns:

  • *RequestData: The parsed request data.
  • error: An error if parsing fails.

func (*RequestData) PlaceField

func (d *RequestData) PlaceField(
	field reflect.Value, fieldInfo reflect.StructField, method string,
) error

PlaceField places the field value in the appropriate part of the request data. It will modify the RequestData object data in-place.

Parameters:

  • field: The field value to process.
  • fieldInfo: The field information.
  • method: The HTTP method for the request.

Returns:

  • error: An error if processing fails.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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