Skip to content

Commit

Permalink
Fix fortunes
Browse files Browse the repository at this point in the history
  • Loading branch information
aerth committed Feb 9, 2017
1 parent e4b2574 commit 4e59dd3
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions 02-internal.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@ package main

import (
"bufio"
"fmt"
"html/template"
"io/ioutil"
"log"
"math/rand"
"net"
Expand Down Expand Up @@ -357,24 +359,27 @@ func newfortune() string {
var fortunes = map[int]string{}

func fortuneInit() {
file, err := os.Open("fortunes.txt")
_, err := os.Open("fortunes.txt")
if err != nil {
if !*quiet {
log.Println("No 'fortunes.txt' file.")
}
return
}
var b []byte
n, err := file.Read(b)

b, err := ioutil.ReadFile("fortunes.txt")
if err != nil {
log.Println("Fortunes:", err)
if !*quiet {
log.Println("Fortunes:", err)
}
return
}
str := string(b[:n])
scanner := bufio.NewScanner(strings.NewReader(str))

scanner := bufio.NewScanner(strings.NewReader(string(b)))
var i = 1
var buf string
for scanner.Scan() {
fmt.Println(scanner.Text())
if scanner.Text() == "" {
if buf != "" {

Expand Down

0 comments on commit 4e59dd3

Please sign in to comment.