# requestid

```go
import "apistock.dev/requestid"
```

Package requestid generates, validates and carries request IDs in a [context.Context](https://pkg.go.dev/context#Context), so HTTP middleware, logging, audit and jobs share one correlation value (ADR-0030).

Stability: pre-1.0 (ADR-0015).

## Constants

### const Header

```go
const Header = "X-Request-ID"
```

Header is the HTTP header carrying the request ID.

### const MaxLength

```go
const MaxLength = 128
```

MaxLength is the longest accepted incoming request ID.

## Functions

### func From

```go
func From(ctx context.Context) string
```

From returns the request ID in ctx, or "".

### func New

```go
func New() string
```

New returns a random request ID such as "req\_9f86d081884c7d65".

### func Valid

```go
func Valid(id string) bool
```

Valid reports whether id is safe to accept from a client: 1 to [MaxLength](#MaxLength) characters of letters, digits, '-', '\_', '.' or ':'. This keeps untrusted IDs from injecting content into logs.

### func With

```go
func With(ctx context.Context, id string) context.Context
```

With returns a copy of ctx carrying id.

