goinaction / code

Source Code for Go In Action examples
4.13k stars 2.37k forks source link

Add go.mod and replaces actions to get go 1.18 to compile (and run). #89

Open mcarifio opened 2 years ago

mcarifio commented 2 years ago

go.mod appears to be needed to compile the chapter2 sample, at least without downloading matchers and search independently in ways I don't yet understand. So figured out how to replace the imports in main.go with local directories mostly through examples and cut and paste. I don't exactly know what I'm doing, but I'll let you cherrypick what changes you want, if any.

tldzyx commented 11 months ago

like this:

exec cd chapter2/sample && go mod init main

/chapter2/sample/go.mod


module main

go 1.21


modify import
> /chapter2/sample/main.go
``` golang
import (
    "log"
    "os"

    _ "main/matchers"
    "main/search"
)

modify import

/chapter2/sample/matchers/rss.go

import (
"encoding/xml"
"errors"
"fmt"
"log"
"main/search"
"net/http"
"regexp"
)

finally, run go run main.go