The IDE is Visual Studio Code. Here is the log when I switching on the debugger:
# _/Users/leon/Documents/Projects/GoLang/TutorialLearningGoForWebDevelopment
/usr/local/go/pkg/tool/darwin_amd64/link: /usr/local/go/pkg/tool/darwin_amd64/link: combining dwarf failed: Unknown load command 0x32 (50)
exit status 2
Process exiting with code: 1
Go version:
go version go1.10.3 darwin/amd64
MacOS version:
Mojave Version 10.14 Beta (18A353d)
Delve version:
Delve Debugger
Version: 1.0.0
Build: $Id: c98a142125d0b17bb11ec0513bde346229b5f533 $
Visual Studio Code Version:
Version 1.26.0-insider (1.26.0-insider)
The launch.json
was nearly automatically generated, with port changed only:
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Launch",
"type": "go",
"request": "launch",
"mode": "debug",
"remotePath": "",
"port": 8080,
"host": "127.0.0.1",
"program": "${fileDirname}",
"env": {},
"args": [],
"showLog": true,
"trace": "verbose"
}
]
}
Finding out some similar problem threads here, I did not find a solution.
I also installed go1.11beta3
, but I do not know how to make it default in terms of VSCode debugging.
One more accurate description of the symptom:
the error was NOT caused on Delve
side, but originated from the very first line of the go
program: package main
Just in case some one might need to read the code, I am including the whole file below:
package main
import (
"database/sql"
"encoding/json"
"fmt"
"html/template"
"io/ioutil"
"net/http"
"net/url"
_ "github.com/mattn/go-sqlite3"
"encoding/xml"
)
type Page struct {
Name string
DBStatus bool
}
type SearchResult struct {
Title string `xml:"title,attr"`
Author string `xml:"author,attr"`
Year string `xml:"hyr,attr"`
ID string `xml:"owi,attr"`
}
type ClassifySearchResponse struct {
Results []SearchResult `xml:"works>work"`
}
type ClassifyBookResponse struct {
BookData struct {
Title string `xml:"title,attr"`
Author string `xml:"author,attr"`
ID string `xml:"owi,attr"`
} `xml:"work"`
Classification struct {
MostPopular string `xml:"sft,attr"`
} `xml:"recommendations>ddc>mostPopular"`
}
func main() {
templates := template.Must(template.ParseFiles("templates/index.html"))
db, _ := sql.Open("sqlite3", "dev_golang.db")
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
p := Page{Name: "Gopher"}
if name := r.FormValue("name"); name != "" {
p.Name = name
}
p.DBStatus = db.Ping() == nil
if err := templates.ExecuteTemplate(w, "index.html", p); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
})
http.HandleFunc("/search", func(w http.ResponseWriter, r *http.Request) {
var results []SearchResult
var err error
if results, err = search(r.FormValue("search")); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
encoder := json.NewEncoder(w)
if err := encoder.Encode(results); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
})
http.HandleFunc("/books/add", func(w http.ResponseWriter, r *http.Request) {
var book ClassifyBookResponse
var err error
if book, err = find(r.FormValue("id")); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
if err = db.Ping(); err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
_, err = db.Exec("insert into books (pk, title, author, id, classification) values (?,?,?,?,?)",
nil,
book.BookData.Title,
book.BookData.Author,
book.BookData.Author,
book.BookData.ID,
book.Classification.MostPopular)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
}
})
fmt.Println(http.ListenAndServe(":8080", nil))
}
func find(id string) (ClassifyBookResponse, error) {
var c ClassifyBookResponse
body, err := classifyAPI("http://classify.oclc.org/classify2/Classify?summary=true&owi=" + url.QueryEscape(id))
if err != nil {
return ClassifyBookResponse{}, err
}
err = xml.Unmarshal(body, &c)
return c, err
}
func search(query string) ([]SearchResult, error) {
var c ClassifySearchResponse
fmt.Println("query, search(): " + query)
body, err := classifyAPI("http://classify.oclc.org/classify2/Classify?summary=true&title=" + url.QueryEscape(query))
if err != nil {
fmt.Println(err.Error())
return []SearchResult{}, err
}
err = xml.Unmarshal(body, &c)
fmt.Println(c.Results)
return c.Results, err
}
func classifyAPI(url string) ([]byte, error) {
var resp *http.Response
var err error
if resp, err = http.Get(url); err != nil {
return []byte{}, err
}
defer resp.Body.Close()
return ioutil.ReadAll(resp.Body)
}
After upgrading GoLang to go1.11 release, I never met this problem any more.
If you installed go via homebrew, do:
brew update
brew upgrade go
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With