gnetlark

package module
v1.0.3 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2025 License: BSD-3-Clause Imports: 6 Imported by: 0

README

gnetlark logo

GoDoc Go Report Card

Fast HTTP server that supports handlers written in Starlark.

Pronounced as "jetlark", just to keep people on their toes.

Features and limitations
  • It's fast, due to the excellent performance of gnet.
  • Starlark is easy to learn and use. It is similar to Python.
  • The selection of functions available from Starlark scripts is currently a bit limited. There is no file or database access.
  • gnetlark offers an easy and fun way to try out the Starlark programming language.
  • Support for providing and calling REST/JSON APIs might be added in the future.
  • Serving static files is currently not supported, unless you embed them.
Installation

Quick installation of the latest version, using Go 1.17 or later:

go install github.com/xyproto/gnetlark/cmd/gnetlark@latest

Another way of building and installing the server:

git clone https://github.com/xyproto/gnetlark
cd gnetlark/cmd/gnetlark
go build
sudo install -Dm755 gnetlark /usr/bin/gnetlark
Configuration

One way to allow access to port 80 on Linux:

sudo setcap cap_net_bind_service=+ep /usr/bin/gnetlark

It's also possible to specify a port with --port or run it as root (not recommended).

Depends on
Screenshot

Screenshot of a page served by index.star, with the server running on port 7711:

screenshot

Served in 0ms:

performance

Example

A short Starlark script for handling requests and outputting "Hello, World!" (hello.star):

def index(status, msg, method, path, date):
    return "HTTP/1.1 " + status + "\r\nServer: gnetlark\r\nDate: " + date + "\r\nContent-Type: text/plain; charset=utf-8\r\n\r\n" + "Hello, World!"

The "Hello World" page can be served by a command like this:

gnetlark -main hello.star -port 7711

General info

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseReq

func ParseReq(data []byte, req *Request) (leftover []byte, err error)

ParseReq is a very simple http request parser. This operation waits for the entire payload to be buffered before returning a valid request.

func Respond

func Respond(to *vt.TextOutput, b []byte, sourceFilename, handlerName, status, msg, method, path string) []byte

Respond will append a valid HTTP response to the provide bytes. The status param should be the code plus text such as "200 OK".

Types

type Request

type Request struct {
	Proto      string
	Method     string
	Path       string
	Query      string
	Head       string
	Body       string
	RemoteAddr string
}

Request contains fields related to a HTTP request, such as HTTP method

Directories

Path Synopsis
cmd
gnetlark command

Jump to

Keyboard shortcuts

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