Skip to main content

openapi_nexus/generators/go/http/
runtime.rs

1//! Hardcoded Go runtime source files.
2//!
3//! The runtime surface is tiny on purpose: one `runtime` package with a
4//! `Client` carrying functional options, an `Authenticator` interface, and
5//! typed `APIError`. Advanced needs (retries, hooks, multi-server) are the
6//! user's responsibility and can be layered on a wrapped `*http.Client`.
7
8use crate::codegen::traits::file_writer::FileInfo;
9
10const CLIENT_GO: &str = include_str!("runtime/client.go.txt");
11const AUTH_GO: &str = include_str!("runtime/auth.go.txt");
12const ERRORS_GO: &str = include_str!("runtime/errors.go.txt");
13
14/// Returns client.go, auth.go, errors.go ready to write.
15///
16/// The category routes these under `<output>/runtime/` via `FileWriter`.
17pub fn runtime_files(header: &str) -> Vec<FileInfo> {
18    vec![
19        FileInfo::runtime("client.go".to_string(), with_header(header, CLIENT_GO)),
20        FileInfo::runtime("auth.go".to_string(), with_header(header, AUTH_GO)),
21        FileInfo::runtime("errors.go".to_string(), with_header(header, ERRORS_GO)),
22    ]
23}
24
25fn with_header(header: &str, body: &str) -> String {
26    let mut out = String::with_capacity(header.len() + body.len());
27    out.push_str(header);
28    out.push_str(body);
29    out
30}