ren

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Aug 16, 2025 License: Apache-2.0 Imports: 18 Imported by: 0

README

ren

Ren is a runtime environment and script packager for Risor scripting language. Ren can be used as a library to provide scripting capabilities to Go applications or as a utility to package/run/test Risor scripts.

Installation

go get github.com/foohq/ren

Usage

// The example code illustrates how to build a package and execute it.
// The code assumes some externalities, such as that specific directories must exist on the local filesystem.
// The packager creates a file cat.zip in the current working directory, if packaging was successful.
package main

import (
	"context"
	"os"

	"github.com/foohq/ren"
	"github.com/foohq/ren/filesystems/local"
	"github.com/foohq/ren/modules"
	"github.com/foohq/ren/packager"
	risoros "github.com/risor-io/risor/os"
)

func getArgs() []string {
	if len(os.Args) > 1 {
		return os.Args[1:]
	}
	return []string{}
}

func main() {
	outputName := "cat.zip"
	// Create a package from a script found in a local directory.
	// Builder recognizes Risor scripts by .risor, .rsr extension.
	// Packager parses, compiles Risor scripts and writes compiled bytecode to .json files.
	// Files are then zipped to create a package file.
	err := packager.Build("/home/user/scripts/cat", outputName)
	if err != nil {
		panic(err)
	}

	// Instantiate a local filesystem.
	// Other compatible synthetic filesystems can be found in standalone repositories.
	// Visit https://github.com/fooHQ?q=filesystem.
	localFS, err := local.NewFS()
	if err != nil {
		panic(err)
	}

	err = ren.RunFile(
		context.Background(),
		outputName,
		ren.WithStdin(os.Stdin),
		ren.WithStdout(os.Stdout),
		ren.WithArgs(getArgs()),
		ren.WithFilesystems(map[string]risoros.FS{
			"file": localFS,
		}),
	)
	if err != nil {
		panic(err)
	}
}

Command line utility

This repository provides a command line utility which can be used to build a package and execute it. The utility can either be built from the source, or downloaded as a pre-compiled binary. For pre-compiled binaries, please refer to repository's releases.

Installing from the source requires devbox:

$ git clone https://github.com/foohq/ren
$ cd ren
$ devbox run build
$ ./build/ren -h

Package format

The package is a .zip file containing compiled Risor scripts encoded as .json files, and other files that were copied from the source directory. A special file entrypoint.json must exist within the package. entrypoint.json file is used to bootstrap a packaged script. entrypoint.json is created by compiling entrypoint.risor (or entrypoint.rsr) which must exist in the source directory. The source file is expected to contain appropriate bootstrapping code tailored for the packaged script.

Please, see examples for more information.

License

This module is distributed under the Apache License Version 2.0 found in the LICENSE file.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Run

func Run(ctx context.Context, reader io.ReaderAt, size int64, opt ...Option) error

func RunBytes

func RunBytes(ctx context.Context, b []byte, opts ...Option) error

func RunFile

func RunFile(ctx context.Context, filename string, opts ...Option) error

func Version

func Version() string

Types

type Error

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

func (*Error) Error

func (e *Error) Error() string

func (*Error) Unwrap

func (e *Error) Unwrap() error

type Option

type Option func(*Options)

func WithArgs added in v0.1.0

func WithArgs(args []string) Option

func WithEnvVar added in v0.1.0

func WithEnvVar(name, value string) Option

func WithExitHandler added in v0.1.0

func WithExitHandler(handler renos.ExitHandler) Option

func WithFilesystems added in v0.1.0

func WithFilesystems(fss map[string]risoros.FS) Option

func WithModule added in v0.1.0

func WithModule(module *object.Module) Option

func WithStdin added in v0.1.0

func WithStdin(file risoros.File) Option

func WithStdout added in v0.1.0

func WithStdout(file risoros.File) Option

func WithWorkDir added in v0.1.0

func WithWorkDir(dir string) Option

type Options

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

func (*Options) Modules added in v0.1.0

func (o *Options) Modules() map[string]any

func (*Options) Options added in v0.1.0

func (o *Options) Options() []renos.Option

type Pipe added in v0.1.0

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

Pipe implements Risor's os.File interface. The type is backed by Go's io.Pipe, therefore, it allows concurrent read/write.

func NewPipe added in v0.1.0

func NewPipe() *Pipe

func (*Pipe) Close added in v0.1.0

func (f *Pipe) Close() error

func (*Pipe) Read added in v0.1.0

func (f *Pipe) Read(p []byte) (int, error)

func (*Pipe) Stat added in v0.1.0

func (f *Pipe) Stat() (risoros.FileInfo, error)

func (*Pipe) Write added in v0.1.0

func (f *Pipe) Write(p []byte) (int, error)

Jump to

Keyboard shortcuts

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