GNDLine beta4 package

GNDLine - Go the GroundLine

This package bundles the GNDLine web runtime together with Go and modern language engines.

Could this tiny file really run?

Yes. This exact file runs as a page.

<%@ LANGUAGE="GND.Go.Yaegi" %>
<%
import . "OpenASP"

func run() {
    Response.Write("<h1>Hello from Go on GNDLine.</h1>")
}
%>

JSON APIs are just as easy

Yes. This exact file runs as a JSON endpoint.

<%@ LANGUAGE="GND.Go.Yaegi" %>
<%
import . "OpenASP"

func run() {
    Response.WriteJSON(map[string]any{
        "ok": true,
        "message": "Hello from GND.Go.Yaegi via .api",
    })
}
%>

What else can it do?

The packaged examples cover these core host and page surfaces:

  • Request
  • Response
  • Session
  • Application
  • Server
  • Routing
  • Authentication
  • Multipart
  • JSON

This package includes these language engines

The packaged page examples run on:

  • Go Yaegi
  • OpenVBS

Pick a Page or an API

This gallery includes both Page(.asp) examples and JSON API(.api) examples. They run the same way; .api is just a clearer URL shape for endpoint-style routes.

Inline ASP page

Here, HTML appears inline inside func run().

<%
func run() {
    title := "inline sample"
%>
<h1><%= title %></h1>
<%
}
%>

Multipart upload page

Upload a file here. The page shows its name, size, and a text preview when possible.

JSON API

This page returns JSON with Response.WriteJSON(...). POST requests are JSON-only.

<%
func run() {
    Response.WriteJSON(map[string]any{
        "ok": true,
    })
}
%>

Minimal vendor package API

This page imports a package from GND.Go.Yaegi.vendor and returns JSON.

<%
import "example.com/srcsample"

func run() {
    Response.WriteJSON(map[string]any{
        "message": srcsample.Message("demo"),
    })
}
            %>

Session toggle

This page changes session state from a query string.

<%
func run() {
    query := Request.QueryString()
    Session.Contents().SetItem("LoginState", first(query.Item("mode")))
}
%>

Auth home

This page reads session state and shows the current login value.

<%
func run() {
    loginState := Session.Contents().Item("LoginState")
}
%>
<p>LoginState=<%= loginState %></p>

SQLite source package API

This page opens SQLite, writes a sample row, and returns JSON.

<%
import "example.com/sqliteapp/store"

func run() {
    db, _ := store.Open("sample.db")
    Response.WriteJSON(map[string]any{
        "ok": true,
    })
}
%>

Mail API

This page adapts BILib.Mail and returns a JSON preview.

<%
import . "BILib"

func run() {
    mail, _ := AsMail(Server.CreateObject("BILib.Mail"))
    Response.WriteJSON(map[string]any{
        "ok": true,
    })
}
%>

Application_OnStart

This global hook stores application-wide values when the app starts.

<script language="GND.Go.Yaegi" runat="server">
func Application_OnStart() {
    Application.Lock()
    Application.Contents().SetItem("SiteName", "GNDLine Beta Package")
    Application.Unlock()
}
</script>

Session_OnStart

This global hook gives each new session a default login state.

<script language="GND.Go.Yaegi" runat="server">
func Session_OnStart() {
    Session.Contents().SetItem("LoginState", "guest")
}
</script>

.Router

Install this in global.asa to register routes at app startup.

<script language="GND.Go.Yaegi" runat="server">
import . "OpenASP"

func Application_OnStart() {
    router, _ := AsRouter(Server.CreateObject(".Router"))
    router.GET("/routed.asp", "/target.asp")
    router.GET("/api/*", "/api/json.api")
    router.GET("/users/{id}.asp", "/auth/home.asp")
    Application.Use(router)
}
</script>

.AuthBySession

Install this in global.asa to protect routes before page entry.

<script language="GND.Go.Yaegi" runat="server">
import . "OpenASP"

func Application_OnStart() {
    auth, _ := AsAuthBySession(Server.CreateObject(".AuthBySession"))
    auth.Item("/member/*", "MemberID", "/login.asp")
    auth.Item("/admin/*", "AdminID", "/login-admin.asp")
    Application.Use(auth)
}
</script>

OpenVBS page

This page uses classic VBScript-style CreateObject(...).

<%@ LANGUAGE="GND.OpenVBS" %>
<%
set dic = CreateObject("Scripting.Dictionary")
dic("foo") = "bar"
%>
<h1><%= dic("foo") %></h1>

Go hosts OpenVBS

This page calls an OpenVBS function from Go.

<%@ LANGUAGE="GND.Go.Yaegi" %>
<script language="GND.OpenVBS" runat="server">
function GetMessage()
    GetMessage = "this is OpenVBS in Go."
end function
</script>
<%
func run() {
    message := GetMessage()
    Response.Write(message)
}
%>

OpenVBS hosts Go

This page calls a Go function from OpenVBS.

<%@ LANGUAGE="GND.OpenVBS" %>
<script language="GND.Go.Yaegi" runat="server">
func GetMessage() string {
    return "this is Go in OpenVBS."
}
</script>
<%
    v = GetMessage()
    Response.Write v
%>

Intentional 500 page

This page ends with invalid Go on purpose.

<%
func run() {
    pageStart("GNDLine 500 Example")
}

this is not valid go
%>

Object gallery

The current package also bundles these object runtimes for OpenVBS page code, plus the optional BILDB plugin.

BILib.Mail

Compose mail fields and send through an SMTP config bag.

<%@ LANGUAGE="GND.OpenVBS" %>
<%
mail = CreateObject("BILib.Mail")
mail.Subject = "hello"
%>

BILib.Dictionary

Use a dictionary object with classic script-style item access.

<%@ LANGUAGE="GND.OpenVBS" %>
<%
dict = CreateObject("BILib.Dictionary")
dict("foo") = "bar"
%>

BILib.RegExp

Use a regular-expression object from OpenVBS page code.

<%@ LANGUAGE="GND.OpenVBS" %>
<%
re = CreateObject("BILib.RegExp")
re.Pattern = "foo+"
%>

BILib.HttpRequest

Use an HTTP client object from OpenVBS page code.

<%@ LANGUAGE="GND.OpenVBS" %>
<%
req = CreateObject("BILib.HttpRequest")
req.Open "GET", "https://example.com/", False
%>

BILib.Stream

Use a byte/text stream object from OpenVBS page code.

<%@ LANGUAGE="GND.OpenVBS" %>
<%
stream = CreateObject("BILib.Stream")
stream.Open
stream.WriteText "hello"
%>

BILDB.Connection

Optional ODBC database plugin. Requires an external ODBC runtime on the host.

<%@ LANGUAGE="GND.OpenVBS" %>
<%
  conn = CreateObject("BILDB.Connection")
  conn.Open "Driver=..."
  conn("SELECT * FROM TMember WHERE name=?", "jenny").foreach(function(r)
      Response.Write r(0).name & ":" & r("id")
      Response.Write r(1).name & ":" & r("name")
      Response.Write r(2).name & ":" & r("time")
  end function)
%>