Skip to content

j0hax/go-openmensa

Repository files navigation

go-openmensa

Go Go Reference Go Report Card

Go API for OpenMensa

Install

The openmensa module functions purely as a library with no executables. To use it in a project, run

$ go get github.com/j0hax/go-openmensa

Example

Following code snippet fetches today's menu and prices for a cafeteria in Hannover:

package main

import (
	"fmt"
	"github.com/j0hax/go-openmensa"
	"log"
)

func main() {
	// Contine Hannover has ID 7
	contine, err := openmensa.GetCanteen(7)
	if err != nil {
		log.Fatal(err)
	}

	// Retrieve the current menu
	menu, err := contine.CurrentMenu()
	if err != nil {
		log.Fatal(err)
	}

	// Print out structured data
	fmt.Printf("%s: %s\n", contine.Name, menu.Day)
	for _, meal := range menu.Meals {
		price := meal.Prices["students"]
		fmt.Printf("- %s (%0.2f€)\n", meal, price)
	}
}

See Also