Skip to content

Commit

Permalink
Merge pull request gythialy#161 from gythialy/feature/example
Browse files Browse the repository at this point in the history
chore: fix fail to build example
  • Loading branch information
gythialy authored Sep 28, 2022
2 parents 08f9860 + 841a72a commit 4d12b28
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 15 deletions.
13 changes: 6 additions & 7 deletions example/.goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
# This is an example goreleaser.yaml file with some sane defaults.
# Make sure to check the documentation at http://goreleaser.com
project_name: go-qlc
project_name: golang-cross-example
env:
- GO111MODULE=on
# - GOPROXY=https://goproxy.cn
before:
hooks:
# before:
# hooks:
# - go get -u github.com/golangci/golangci-lint/cmd/golangci-lint
# you may remove this if you don't use vgo
# - go mod download
# you may remove this if you don't need go generate
# - go generate ./..
builds:
# Mainnet

- id: example-darwin-amd64
binary: example
env:
Expand All @@ -28,8 +28,8 @@ builds:
binary: example
env:
- CGO_ENABLED=1
- CC=aarch64-apple-darwin20.2-clang
- CXX=aarch64-apple-darwin20.2-clang++
- CC=aarch64-apple-darwin21.4-clang
- CXX=aarch64-apple-darwin21.4-clang++
main: ./main.go
goos:
- darwin
Expand Down Expand Up @@ -80,7 +80,6 @@ checksum:
snapshot:
name_template: SNAPSHOT-{{.ShortCommit}}


# release:
# github:
# owner: gythialy
Expand Down
2 changes: 1 addition & 1 deletion example/go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/gythialy/golang-cross-example

go 1.16
go 1.18

require github.com/mattn/go-sqlite3 v1.14.7
18 changes: 11 additions & 7 deletions example/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,22 @@ import (

// https://www.codeproject.com/Articles/5261771/Golang-SQLite-Simple-Example
func main() {
os.Remove("sqlite-database.db") // I delete the file to avoid duplicated records.
_ = os.Remove("sqlite-database.db") // I delete the file to avoid duplicated records.
// SQLite is a file based database.

log.Println("Creating sqlite-database.db...")
file, err := os.Create("sqlite-database.db") // Create SQLite file
if err != nil {
log.Fatal(err.Error())
}
file.Close()
_ = file.Close()
log.Println("sqlite-database.db created")

sqliteDatabase, _ := sql.Open("sqlite3", "./sqlite-database.db") // Open the created SQLite File
defer sqliteDatabase.Close() // Defer Closing the database
createTable(sqliteDatabase) // Create Database Tables
defer func(sqliteDatabase *sql.DB) {
_ = sqliteDatabase.Close()
}(sqliteDatabase) // Defer Closing the database
createTable(sqliteDatabase) // Create Database Tables

// INSERT RECORDS
insertStudent(sqliteDatabase, "0001", "Liana Kim", "Bachelor")
Expand Down Expand Up @@ -53,7 +55,7 @@ func createTable(db *sql.DB) {
if err != nil {
log.Fatal(err.Error())
}
statement.Exec() // Execute SQL Statements
_, _ = statement.Exec() // Execute SQL Statements
log.Println("student table created")
}

Expand All @@ -77,13 +79,15 @@ func displayStudents(db *sql.DB) {
if err != nil {
log.Fatal(err)
}
defer row.Close()
defer func(row *sql.Rows) {
_ = row.Close()
}(row)
for row.Next() { // Iterate and fetch the records from result cursor
var id int
var code string
var name string
var program string
row.Scan(&id, &code, &name, &program)
_ = row.Scan(&id, &code, &name, &program)
log.Println("Student: ", code, " ", name, " ", program)
}
}

0 comments on commit 4d12b28

Please sign in to comment.