GithubHelp home page GithubHelp logo

xyproto / gnetlark Goto Github PK

View Code? Open in Web Editor NEW
13.0 4.0 0.0 3.23 MB

:bird: Fast HTTP server that supports handlers written in Starlark

License: BSD 3-Clause "New" or "Revised" License

Go 52.92% Starlark 47.08%
gnet starlark http server minimalistic

gnetlark's Introduction

gnetlark logo

Build Status 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 development 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

gnetlark's People

Contributors

xyproto avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

gnetlark's Issues

Add support for interacting with SQLite databases

Currently, gnetlark is fast and sweet, but it completely lacks a way to communicate with a database or interact with the filesystem. With support for SQLite, there would be at least one way to interact with the host system, and to have some sort of state.

This is a feature request for adding SQLite support, so that accessing a SQLite database is possible, from within the Starlark language, when running gnetlark.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.