Signal: killed Process finished with exit code 1, what I am wrong?

Here is main.go

package main

import (
	"fmt"
	"net/http"
	"html/template"
	_ "github.com/mattn/go-sqlite3"
	"database/sql"
)

type Page struct {
	Name string
	DBStatus bool
}

func main() {
	templates := template.Must(template.ParseFiles("templates/index.html"))

	db, _ := sql.Open("sqlite3", "dev.db")

	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		p := Page{Name: "Gopher", DBStatus: false}
		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)
		}

		db.Close()
	})

	fmt.Println(http.ListenAndServe(":8080", nil))
}

and here is my index.html

<html>
<head></head>
<body>
<p>Hello, {{.Name}}</p>

{{if .DBStatus}}
<p>The database connection is alive!</p>
{{else}}
<p>The database connection is dead!</p>
{{end}}
</body>
</html>

When I run main.go I get the message

signal: killed

Process finished with exit code 1

I have install the go get github.com/mattn/go-sqlite3

Please check the returned error in sql.Open!

I was unable to replicate the error.

go1.8.1, macOS 10.12.4

1 Like

Yes @nathankerr the same my env.

Wrong version of libsqlite3 perhaps?

github.com/mattn/go-sqlite3 embeds sqlite and does not use an external version.

any solution to make it works @nathankerr

I could not replicate the problem. I tried to replicate it again, but could not.

I ran go build, ran the resulting executable, pointed my browser at http://127.0.0.1:8080 and received:

Hello, Gopher

The database connection is alive!

My process was not killed. I got the result I expected from the program. It works for me.

Since I can’t find the problem you described, I can’t find a solution for it.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.