Skip to content

Commit

Permalink
Linting.
Browse files Browse the repository at this point in the history
  • Loading branch information
ibiscum committed Feb 16, 2024
1 parent f85a30c commit 80af00d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 9 deletions.
11 changes: 7 additions & 4 deletions cmd/Chapter01/Example01.02/ex01.02.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,36 +7,39 @@ import (
"log"
"math/rand"
"strconv"
"time"
)

// Taken from: https://en.wiktionary.org/wiki/Hello_World#Translations
var helloList = []string{
"Hello, world",
"Καλημέρα κόσμε",
"こんにちは世界",
"سلام دنیا‎",
// "سلام دنیا‎",
"سلام دنیا\u200e",
"Привет, мир",
}

func main() {
// Seed random number generator using the current time
rand.Seed(time.Now().UnixNano())
// Generate a random number in the range of out list
index := rand.Intn(len(helloList))

// Call a function and receive multiple return values
msg, err := hello(index)

// Handle any errors
if err != nil {
log.Fatal(err)
}

// Print our message to the console
fmt.Println(msg)
}

func hello(index int) (string, error) {
if index < 0 || index > len(helloList)-1 {
// Create an error, convert the int type to a string
return "", errors.New("out of range: " + strconv.Itoa(index))
}

return helloList[index], nil
}
7 changes: 6 additions & 1 deletion cmd/Chapter14/Exercise14.04/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,16 @@ func (srv server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if err != nil {
log.Fatal(err)
}

err = os.WriteFile(fmt.Sprintf("./%s", uploadedFileHeader.Filename), fileContent, 0666)
if err != nil {
log.Fatal(err)
}
w.Write([]byte(fmt.Sprintf("%s Uploaded!", uploadedFileHeader.Filename)))

_, err = w.Write([]byte(fmt.Sprintf("%s Uploaded!", uploadedFileHeader.Filename)))
if err != nil {
log.Fatal(err)
}
}

func main() {
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package main

import (
"io/ioutil"
"net/http"
"net/http/httptest"
"os"
"strings"
"testing"
)
Expand All @@ -13,12 +13,12 @@ func TestStatic(t *testing.T) {
w := httptest.NewRecorder()
http.ServeFile(w, r, "./index.html")

content, err := ioutil.ReadFile("index.html")
content, err := os.ReadFile("index.html")
if err != nil {
t.Error(err)
}
//rpl := strings.NewReplacer(" ","","\n","")
if w.Body.String() != string(content) {
t.Errorf("%s\n%s", string(content),w.Body.String())
t.Errorf("%s\n%s", string(content), w.Body.String())
}
}
}

0 comments on commit 80af00d

Please sign in to comment.