runtime.link

module
v0.0.0-...-ec3616b Latest Latest
Warning

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

Go to latest
Published: Feb 24, 2025 License: 0BSD

README

The runtime.link project provides a dictionary for representing software interfaces through Go source. It also provides several Go linkers that enable you to link to these interfaces at runtime. They can be connected via network protocols (ie. HTTP), through command line interfaces, or through supported platform-native ABIs.

The project is still in development and although we don't plan to make any major changes to established components before the first stable release, there may be continue to be minor breaking changes here and there as we work to refine the exported interfaces.

Example:

// Package example provides the specification for the runtime.link example API.
package example

import (
	"log"
	"os"

	"runtime.link/api"
)

// API specification structure, typically named API for general structures, may
// be more suitably named Functions, Library or Command when the API is
// restricted to a specific runtime.link layer. Any Go comments in the source
// are intended to document design notes and ideas. This leaves Go struct tags
// for recording developer-facing documentation.
type API struct {
	api.Specification `api:"Example" cmd:"example" lib:"libexample"
		is an example of a runtime.link API structure.` // this section of the tag contains documentation.

	// HelloWorld includes runtime.link tags that specify how the function is called
	// across different link-layers. Typically, a context.Context argument and error
	// return value should be included here, they are omitted here for brevity.
	HelloWorld func() string `cmdl:"hello_world" link:"example_helloworld func()$char" rest:"GET /hello_world"
		returns the string "Hello World"` // documentation for the function.
}

// New returns an implementation of the API. This doesn't have to be defined in the
// same package and may not even be implemented in Go. This will often be the case when
// representing an external API controlled by a third-party.
func New() API {
	return API{
		HelloWorld: func() string {
			return "Hello World"
		},
	}
}

More Practical Examples

Runtime Linkers.

Each linker lives under the api package and enables an API to be linked against a host implementation via a standard communication protocol. A linker can also serve a host implementation written in Go.

Currently available runtime.linkers include:

* cmdl - parse command line arguments or execute command line programs.
* link - generate c-shared export directives or dynamicaly link to shared libraries (via ABI).
* rest - link to, or host a REST API server over the network.
* stub - create a stub implementation of an API, that returns empty values or errors.
* xray - debug linkers with API call introspection.

Our Design Values

  1. Full readable words for exported identifiers rather than abbreviations ie. PutString over puts.
  2. Acronyms as package names and/or as a suffix, rather than mixed use ie. TheExampleAPI over TheAPIExample.
  3. Explicitly tagged types that define data relationships rather than implicit use of primitives. Customer CustomerID over Customer string.
  4. Don't stutter exported identifiers. customer.Account over customer.Customer.

Contribution Guidance

Apart from what's on the Roadmap, we cannot accept any pull requests for new top level packages at this time, although you are welcome to start a GitHub Discussion for any ideas you may have, our current goal for runtime.link is to stick to a well-defined and cohesive design space.

runtime.link aims to be dependency free, we will not accept any pull requests that add any additional Go dependencies to the project.

NOTE: we adopt a different convention for Go struct tags, which are permitted to be multi-line and include inline-documentation on subsequent lines of the tag. This can raise a warning with Go linters, so we recommend using the following configurations:

govet go vet -structtag=false ./...

VS Code + gopls

"go.vetFlags": [
    "-structtag=false"
],
"gopls": {
    "analyses": {
        "structtag": false
    },
},

Zed:

"lsp": {
  "gopls": {
    "initialization_options": {
      "analyses": {
        "structtag": false
      }
    }
  }
}

golangci-lint.yml

linters-settings:
  govet:
    disable:
      - structtag # support runtime.link convention.

Roadmap

  • Support for additional linkers, such as mock, grpc, soap, jrpc, xrpc, and sock.

Directories

Path Synopsis
api
Package api defines the standard runtime reflection representation for a runtime.link API structure.
Package api defines the standard runtime reflection representation for a runtime.link API structure.
call
Package call provides shared library linker for runtime.link (WORK-IN-PROGRESS).
Package call provides shared library linker for runtime.link (WORK-IN-PROGRESS).
call/internal/abi
Package abi provides an interface to the platform-standard ABI calling conventions and type system (typically C).
Package abi provides an interface to the platform-standard ABI calling conventions and type system (typically C).
call/internal/bin
Package bin enables you to represent binary formats.
Package bin enables you to represent binary formats.
call/internal/bin/std/cpu/amd64
Package amd64 provides an instruction set specification for the AMD64 architecture.
Package amd64 provides an instruction set specification for the AMD64 architecture.
call/internal/bin/std/cpu/arm64
Package arm64 provides an instruction set specification for the ARM64 architecture.
Package arm64 provides an instruction set specification for the ARM64 architecture.
call/internal/cgo
Code generated by gen/gen.go.
Code generated by gen/gen.go.
call/internal/dll
Package dll provides methods for dynamically loading shared libraries and symbol lookup.
Package dll provides methods for dynamically loading shared libraries and symbol lookup.
call/internal/ffi
Package ffi provides information about the platform-native C ABI types.
Package ffi provides information about the platform-native C ABI types.
call/internal/jit
Package jit provides a safe alternative to reflect.MakeFunc with support for transparent optimisation.
Package jit provides a safe alternative to reflect.MakeFunc with support for transparent optimisation.
cmdl
Package cmdl provides a command-line interface linker for runtime.link.
Package cmdl provides a command-line interface linker for runtime.link.
data
Package data provides ways to declare validation constraints on values, these constraints can be reflected upon at runtime.
Package data provides ways to declare validation constraints on values, these constraints can be reflected upon at runtime.
example/petstore
Package petstore serves as an example for how to represent a REST API specification.
Package petstore serves as an example for how to represent a REST API specification.
fmts
Package fmts provides a format specification API linker.
Package fmts provides a format specification API linker.
internal/http
Package http provides an extendable shell API based on http.
Package http provides an extendable shell API based on http.
internal/oas
Package oas provides a representation of the OpenAPI Specification (OAS) Version 3.1.0
Package oas provides a representation of the OpenAPI Specification (OAS) Version 3.1.0
internal/rtags
Package rtags provides methods for reading a rest.Tag, do not make this public, instead extend the rest.Tag with methods if required.
Package rtags provides methods for reading a rest.Tag, do not make this public, instead extend the rest.Tag with methods if required.
pair
Package pair can represent 1:1 mappings between two different APIs, such that validation errors are transformed.
Package pair can represent 1:1 mappings between two different APIs, such that validation errors are transformed.
rest
Package rest provides a REST API transport.
Package rest provides a REST API transport.
stub
Package stub provides a stub api.Linker that returns empty values and specific errors.
Package stub provides a stub api.Linker that returns empty values and specific errors.
xray
Package xray provides standard means for introspecting the internal operational state of an [api.Linker].
Package xray provides standard means for introspecting the internal operational state of an [api.Linker].
Package box provides mechanisms for binary encoding and decoding of the "Binary Object X" format.
Package box provides mechanisms for binary encoding and decoding of the "Binary Object X" format.
cpu
Package ffi provides a bridge for data types that cross runtime boundaries.
Package ffi provides a bridge for data types that cross runtime boundaries.
Package mmm provides a way to manually manage memory and resource lifetimes with protections against unsafe double-free and use-after-free errors.
Package mmm provides a way to manually manage memory and resource lifetimes with protections against unsafe double-free and use-after-free errors.
pii
Package qnq provides a representation for message queuing, event handling and callback flows.
Package qnq provides a representation for message queuing, event handling and callback flows.
ram
sql
Package sql defines a data map type with support for type-safe structured queries.
Package sql defines a data map type with support for type-safe structured queries.
std/sodium
Package sodium provides a specification for the SODIUM standard database interface.
Package sodium provides a specification for the SODIUM standard database interface.
Package xyz provides switch types, tuples and a binary sequence tag.
Package xyz provides switch types, tuples and a binary sequence tag.

Jump to

Keyboard shortcuts

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