How to do it...

  1. Install the github.com/go-sql-driver/mysql and github.com/gorilla/mux packages, using the go get command, as follows:
$ go get github.com/go-sql-driver/mysql$ go get github.com/gorilla/mux
  1. Create create-record-mysql.go. Then we connect to the MySQL database and perform an INSERT query to create an employee record, as follows:
package mainimport (  "database/sql"  "fmt"  "log"  "net/http"  "strconv"  "github.com/go-sql-driver/mysql"  "github.com/gorilla/mux")const (  CONN_HOST = "localhost"  CONN_PORT = "8080"  DRIVER_NAME = "mysql"  DATA_SOURCE_NAME = "root:password@/mydb")var db *sql.DBvar connectionError errorfunc init() {  db, connectionError = sql.Open(DRIVER_NAME, DATA_SOURCE_NAME)  if connectionError != nil   { log.Fatal("error ...

Get Go Web Development Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.