Fortune in Golang - Proof of Concept

May 13, 2013
golang fortune programming go

This is what I built at today’s Memphis Hackathon. Thanks a billion to the Memphis Makers and their MakerSpace! There is plenty more to learn with Golang - I am just glad to have read some line from a file and split them on a delimiter.

package main

import (

func main() {

func nthFortune(n int) string {
    filename := "/usr/local/Cellar/fortune/9708/share/games/fortunes/pets"
    theFile, _ := os.Open(filename)
    fileBuf := bufio.NewReader(theFile)

    for i := 0; i < n; i++  {

    theLine, _ := fileBuf.ReadString('%')
    cutoff := len(theLine) - 1

    return theLine[:cutoff]

Output: # go run fortune.go Cats, no less liquid than their shadows, offer no angles to the wind.