Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Downgrade Go version to 1.20 #93

Merged
merged 2 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@ on:
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
go: [ '1.20', '>=1.21' ]

services:
sqld:
Expand All @@ -28,6 +31,7 @@ jobs:
with:
go-version-file: "go.mod"
cache: true
go-version: ${{ matrix.go }}

- name: Format
run: if [ "$(gofmt -s -l . | wc -l)" -gt 0 ]; then exit 1; fi
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
module github.com/libsql/libsql-client-go

go 1.21
go 1.20

require (
github.com/antlr/antlr4/runtime/Go/antlr/v4 v4.0.0-20230512164433-5d1fd1a340c9
Expand Down
20 changes: 17 additions & 3 deletions libsql/sql.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"errors"
"fmt"
"net/url"
"slices"
"strings"

"github.com/libsql/libsql-client-go/libsql/internal/http"
Expand Down Expand Up @@ -78,7 +77,7 @@ func (c config) connector(dbPath string) (driver.Connector, error) {
expectedDrivers := []string{"sqlite", "sqlite3"}
presentDrivers := sql.Drivers()
for _, expectedDriver := range expectedDrivers {
if slices.Contains(presentDrivers, expectedDriver) {
if Contains(presentDrivers, expectedDriver) {
db, err := sql.Open(expectedDriver, dbPath)
if err != nil {
return nil, err
Expand Down Expand Up @@ -274,7 +273,7 @@ func (d Driver) Open(dbUrl string) (driver.Conn, error) {
expectedDrivers := []string{"sqlite", "sqlite3"}
presentDrivers := sql.Drivers()
for _, expectedDriver := range expectedDrivers {
if slices.Contains(presentDrivers, expectedDriver) {
if Contains(presentDrivers, expectedDriver) {
db, err := sql.Open(expectedDriver, dbUrl)
if err != nil {
return nil, err
Expand Down Expand Up @@ -332,3 +331,18 @@ func (d Driver) Open(dbUrl string) (driver.Conn, error) {
func init() {
sql.Register("libsql", Driver{})
}

// backported from Go 1.21

func Contains[S ~[]E, E comparable](s S, v E) bool {
return Index(s, v) >= 0
}

func Index[S ~[]E, E comparable](s S, v E) int {
for i := range s {
if v == s[i] {
return i
}
}
return -1
}
Loading