http

package
v0.36.0 Latest Latest
Warning

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

Go to latest
Published: Mar 21, 2026 License: AGPL-3.0 Imports: 3 Imported by: 0

README

HTTP Utilities

The http package provides HTTP-related utility functions for Go applications.

Installation

go get github.com/dracory/base/http

Usage

SafeCloseResponseBody

Safely closes an HTTP response body with proper error handling and logging.

import "github.com/dracory/base/http"

resp, err := http.Get("https://example.com")
if err != nil {
    // handle error
}
defer http.SafeCloseResponseBody(resp.Body)

// Use response body...

This utility function ensures consistent error handling and logging across the application. It safely handles nil responses and logs any closing errors without panicking.

Redirect

Performs an HTTP redirect to the specified URL using temporary redirect (307).

import "github.com/dracory/base/http"

func handler(w http.ResponseWriter, r *http.Request) string {
    // Redirect to login page
    return http.Redirect(w, r, "/login")
}

The function wraps the standard http.Redirect for consistency across the codebase and returns an empty string for compatibility with controller return patterns.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Redirect

func Redirect(w http.ResponseWriter, r *http.Request, url string) string

Redirect performs an HTTP redirect to the specified URL using temporary redirect (307). It wraps the standard http.Redirect function for consistency across the codebase.

Parameters:

  • w: http.ResponseWriter to write the redirect response
  • r: *http.Request representing the current request
  • url: string target URL to redirect to

Returns:

  • string: empty string (for compatibility with controller return patterns)

func SafeCloseResponseBody

func SafeCloseResponseBody(body io.Closer)

SafeCloseResponseBody safely closes an HTTP response body with proper error handling. This utility function ensures consistent error handling and logging across the application.

Types

This section is empty.

Jump to

Keyboard shortcuts

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