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: ? modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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