bodybackend

package
v0.0.3 Latest Latest
Warning

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

Go to latest
Published: Nov 12, 2026 License: AGPL-3.0 Imports: 23 Imported by: 0

Documentation

Overview

Package bodybackend is the body service: a user's scale readings and DEXA scans, the estimates computed from them and the rules for importing readings from a source such as Withings.

It knows nothing about who a user is. The main backend authenticates people and calls this service with a short-lived signed token for one user and one scope (see pkg/shared/bodyapi); the service checks the token and acts on exactly that user's data. It never imports the main backend, the frontend, the workers or anything that signs people in.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*Service)

Option changes how New builds a Service.

func WithSpareSecrets

func WithSpareSecrets(secrets ...string) Option

WithSpareSecrets makes the service accept these secrets too, next to the first one, so that the secret can be rotated without downtime: the main backend sends the first line of its file, and the service accepts every line of its own until the old one is removed.

func WithVersion

func WithVersion(v string) Option

WithVersion names the running program. It is part of the estimates' ETag, so a new version never answers "not modified" for a result an older algorithm made.

type Service

type Service struct {
	// contains filtered or unexported fields
}

Service is the body service. Use Handler to serve it.

func New

func New(st store.BodyStore, secret string, verifier *bodyapi.Verifier, opts ...Option) (*Service, error)

New returns a Service over a store. secret is the shared secret every call must carry, and verifier holds the public keys of the main backend.

func NewInProcess

func NewInProcess(st store.BodyStore, opts ...Option) (*bodyapi.Client, *Service, error)

NewInProcess runs a body service over st inside this process and returns it with a client for it. The combined `serve` mode uses it, and so does a main backend that has no body service of its own to call. The client talks to the service through the same handler, headers and tokens as a separate process would, with a secret and a signing key made for this run only.

func (*Service) CacheStats

func (s *Service) CacheStats() (hits, misses int64)

CacheStats reports how often an estimate came from the cache, for tests and diagnostics.

func (*Service) Handler

func (s *Service) Handler() http.Handler

Handler serves the body API.

func (*Service) SetVersion

func (s *Service) SetVersion(v string)

SetVersion names the running program, for services built before it is known (see WithVersion). Call it before the service takes requests.

Jump to

Keyboard shortcuts

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