bodyfile

package
v1.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 8, 2026 License: MIT Imports: 4 Imported by: 0

Documentation

Overview

Package bodyfile opens the files bodies are read from, such as a reply's body_file. A body file name can be a template, and a name rendered from request data must not reach outside the directory the mock's author chose.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FromDir

func FromDir(dir string) (string, error)

FromDir returns the path that leads from dir to the working directory, such as ../.., or "" when they are one.

func Open

func Open(dir, source, name string) (*os.File, error)

Open opens the body file name, which is what source rendered to: the same text when source isn't a template, or has no actions. A relative name starts at dir; "" is the working directory.

A name written as it is opens as it is. A name that differs from its source came from template data, such as the request. The leading path elements it shares with its source were written by the mock's author, and name the directory the rest must stay inside: the rest opens through os.Root, which refuses absolute names, ".." that leaves the directory, and symbolic links that point out of it. So "files/{{ .Request.URL.Query.Get "f" }}" opens files in dir/files only.

func Path

func Path(dir, name string) string

Path returns the body file name joined to dir, where a relative name opens from, such as the mock file's directory: it opens the same file from the working directory, as a description loaded back opens it. The name stays as it is, since it can be a template.

func Relocate

func Relocate(obj any, toWD string)

Relocate makes the body_file of obj, an object of a mock's description, which opens from the working directory when it is relative, open from the directory toWD leads from to it, as FromDir returns: it puts toWD before it. The name stays as it is otherwise, since it can be a template.

Types

This section is empty.

Jump to

Keyboard shortcuts

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