Skip to content
/ ranna-go Public

A client implementation for ranna-go/ranna written in Golang

License

Notifications You must be signed in to change notification settings

lus/ranna-go

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

7 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

ranna-go

ranna-go is a Golang client implementation for the code execution sandbox ranna.

Please note: ranna already provides a Golang client implementation here. If this is enough for you, go for it. With this library I aim at providing a generic client for ranna plus the according other microservices (snippets).

Usage

Download the library:

go get github.com/lus/ranna-go

Code execution

package main

import "github.com/lus/ranna-go/ranna"

func main() {
    client := ranna.NewClient("https://public.ranna.zekro.de")
    
    // Retrieve all registered language specifications
    specs, err := client.Specs()
    if err != nil {
        panic(err)
    }
    // specs now contains a map of language specifications

    // Execute Go code
    code := `
        package main

        import "fmt"

        func main() {
            fmt.Println("Hello, ranna!")
        }
    `
    request := &ranna.ExecutionRequest{
        Language:    "go",
        Code:        code,
        Arguments:   []string{},
        Environment: map[string]string{},
    }
    result, err := client.Execute(request)
    if err != nil {
        panic(err)
    }
    // result contains stdout, stderr and the execution duration
}

Snippets

package main

import "github.com/lus/ranna-go/snippets"

func main() {
    client := snippets.NewClient("https://snippets.ranna.zekro.de")

    // Create a Go code sippet
    code := `
        package main

        import "fmt"

        func main() {
            fmt.Println("Hello, ranna!")
        }
    `
    snippet := &snippets.Snippet{
        Language: "go",
        Code:     code,
    }
    created, err := client.Create(snippet)
    if err != nil {
        panic(err)
    }
    // created contains the created snippet

    // Retrieve a code snippet
    retrieved, err := client.Snippet("snippet")
    if err != nil {
        panic(err)
    }
    // retrieved contains the retrieved snippet
}

About

A client implementation for ranna-go/ranna written in Golang

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages