TUN-2243: Revert "STOR-519: Add db-connect, a SQL over HTTPS server"
This reverts commit 5da2109811
.
This commit is contained in:
parent
c3c88cc31e
commit
4e1df1a211
|
@ -1,14 +1,6 @@
|
|||
# This file is autogenerated, do not edit; changes may be undone by the next 'dep ensure'.
|
||||
|
||||
|
||||
[[projects]]
|
||||
digest = "1:3d3a509c5ba327e8573bb57f9da8430c63a46a06886eb1d2ffc8af4e76f31c72"
|
||||
name = "cloud.google.com/go"
|
||||
packages = ["civil"]
|
||||
pruneopts = "UT"
|
||||
revision = "cdaaf98f9226c39dc162b8e55083b2fbc67b4674"
|
||||
version = "v0.43.0"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:9f3b30d9f8e0d7040f729b82dcbc8f0dead820a133b3147ce355fc451f32d761"
|
||||
name = "github.com/BurntSushi/toml"
|
||||
|
@ -17,14 +9,6 @@
|
|||
revision = "3012a1dbe2e4bd1391d42b32f0577cb7bbc7f005"
|
||||
version = "v0.3.1"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:c84a587136cb69cecc11f3dbe9f9001444044c0dba74997b07f7e4c150b07cda"
|
||||
name = "github.com/DATA-DOG/go-sqlmock"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "3f9954f6f6697845b082ca57995849ddf614f450"
|
||||
version = "v1.3.3"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:1a200e7e73293b75eb8e5c93d023b5472663432da0b663e1532624fcfede9ca8"
|
||||
|
@ -63,14 +47,6 @@
|
|||
pruneopts = "UT"
|
||||
revision = "333127dbecfcc23a8db7d9a4f52785d23aff44a1"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:05756b73bf7eae03d6f6c5f0ae83de42ce296e7d83336563dd9ce2072106d5e6"
|
||||
name = "github.com/cloudflare/golz4"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "ef862a3cdc58a6f1fee4e3af3d44fbe279194cde"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:3f9506ee991cdee1f05bf0cd3e34b5cd922dc00d6a950fb4beb4e07ab1c4d3d1"
|
||||
name = "github.com/coredns/coredns"
|
||||
|
@ -105,12 +81,11 @@
|
|||
version = "v1.2.0"
|
||||
|
||||
[[projects]]
|
||||
branch = "v2"
|
||||
digest = "1:ca6ce07b0d28c6044411b9c966cd845233e27c2ff91d08a3a869631f329c9918"
|
||||
digest = "1:6f70106e7bc1c803e8a0a4519e09c12d154771acfa2559206e97b033bbd1dd38"
|
||||
name = "github.com/coreos/go-oidc"
|
||||
packages = ["."]
|
||||
packages = ["jose"]
|
||||
pruneopts = "UT"
|
||||
revision = "274971e2c94cd6fb17614979e2899edbc81af146"
|
||||
revision = "a93f71fdfe73d2c0f5413c0565eea0af6523a6df"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:1da3a221f0bc090792d3a2a080ff09008427c0e0f0533a4ed6abd8994421da73"
|
||||
|
@ -138,15 +113,11 @@
|
|||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:27cbe99893a40975358d20736d80adc95ef395d3bf5923f802f3de259533c94a"
|
||||
name = "github.com/denisenkom/go-mssqldb"
|
||||
packages = [
|
||||
".",
|
||||
"internal/cp",
|
||||
"internal/querytext",
|
||||
]
|
||||
digest = "1:c013ffc6e15f9f898078f9d38441c68b228aa7b899659452170250ccb27f5f1e"
|
||||
name = "github.com/elgs/gosqljson"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "11b2859924c1e3c3da056fd4e0976b93883f3545"
|
||||
revision = "027aa4915315a0b2825c0f025cea347829b974fa"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:d4268b2a09b1f736633577c4ac93f2a5356c73742fff5344e2451aeec60a7ad0"
|
||||
|
@ -170,14 +141,6 @@
|
|||
pruneopts = "UT"
|
||||
revision = "75cf19382434e82df4dd84953f566b8ad23d6e9e"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:296cda2c4a6a7a54964d7b3b0815e2aed215da75217b72033060ffb1c4e4b6ae"
|
||||
name = "github.com/felixge/httpsnoop"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "eadd4fad6aac69ae62379194fe0219f3dbc80fd3"
|
||||
version = "v1.0.0"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:50a46ab1d5edbbdd55125b4d37f1bf503d0807c26461f9ad7b358d6006641d09"
|
||||
|
@ -201,14 +164,6 @@
|
|||
revision = "5b6cc7030f17095c0cf23bb063b0bfe824fe5f8b"
|
||||
version = "v0.2.2"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:ec6f9bf5e274c833c911923c9193867f3f18788c461f76f05f62bb1510e0ae65"
|
||||
name = "github.com/go-sql-driver/mysql"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "72cd26f257d44c1114970e19afddcd812016007e"
|
||||
version = "v1.4.1"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:3e6afc3ed8a72949aa735c00fddc23427dc9384ccfd51cf0d91a412e668da632"
|
||||
|
@ -217,14 +172,6 @@
|
|||
pruneopts = "UT"
|
||||
revision = "604e922904d35e97f98a774db7881f049cd8d970"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:01745416ed734d0dbd8f2a25344536e399ee60319654873da12b107e9e3cb309"
|
||||
name = "github.com/golang/gddo"
|
||||
packages = ["httputil/header"]
|
||||
pruneopts = "UT"
|
||||
revision = "af0f2af80721261f4d211b2c9563f7b46b2aab06"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:239c4c7fd2159585454003d9be7207167970194216193a8a210b8d29576f19c9"
|
||||
name = "github.com/golang/protobuf"
|
||||
|
@ -271,17 +218,6 @@
|
|||
pruneopts = "UT"
|
||||
revision = "8e809c8a86450a29b90dcc9efbf062d0fe6d9746"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:6c41d4f998a03b6604227ccad36edaed6126c397e5d78709ef4814a1145a6757"
|
||||
name = "github.com/jmoiron/sqlx"
|
||||
packages = [
|
||||
".",
|
||||
"reflectx",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "d161d7a76b5661016ad0b085869f77fd410f3e6a"
|
||||
version = "v1.2.0"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:31e761d97c76151dde79e9d28964a812c46efc5baee4085b86f68f0c654450de"
|
||||
name = "github.com/konsorten/go-windows-terminal-sequences"
|
||||
|
@ -291,26 +227,7 @@
|
|||
version = "v1.0.2"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:177a18252d40bf39a867876456854717780b0b1212fdae231d31e93b6f885d80"
|
||||
name = "github.com/kshvakov/clickhouse"
|
||||
packages = [
|
||||
".",
|
||||
"lib/binary",
|
||||
"lib/cityhash102",
|
||||
"lib/column",
|
||||
"lib/data",
|
||||
"lib/leakypool",
|
||||
"lib/lz4",
|
||||
"lib/protocol",
|
||||
"lib/types",
|
||||
"lib/writebuffer",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "43e176a8d165376662f4d67203c71cc8a027c86b"
|
||||
version = "v1.3.9"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:12cb143f2148bf54bcd9fe622abac17325e85eeb1d84b8ec6caf1c80232108fd"
|
||||
digest = "1:bc1c0be40c67b6b4aee09d7508d5a2a52c1c116b1fa43806dad2b0d6b4d4003b"
|
||||
name = "github.com/lib/pq"
|
||||
packages = [
|
||||
".",
|
||||
|
@ -318,8 +235,8 @@
|
|||
"scram",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "3427c32cb71afc948325f299f040e53c1dd78979"
|
||||
version = "v1.2.0"
|
||||
revision = "51e2106eed1cea199c802d2a49e91e2491b02056"
|
||||
version = "v1.1.0"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:2fa7b0155cd54479a755c629de26f888a918e13f8857a2c442205d825368e084"
|
||||
|
@ -337,14 +254,6 @@
|
|||
revision = "c2a7a6ca930a4cd0bc33a3f298eb71960732a3a7"
|
||||
version = "v0.0.7"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:79e87abf06b873987dee86598950f5b51732ac454d5a5cab6445a14330e6c9e3"
|
||||
name = "github.com/mattn/go-sqlite3"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "b612a2feea6aa87c6d052d9086572551df06497e"
|
||||
version = "v1.11.0"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:ff5ebae34cfbf047d505ee150de27e60570e8c394b3b8fdbb720ff6ac71985fc"
|
||||
name = "github.com/matttproud/golang_protobuf_extensions"
|
||||
|
@ -380,14 +289,6 @@
|
|||
revision = "af06845cf3004701891bf4fdb884bfe4920b3727"
|
||||
version = "v1.1.0"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:dd3d50b46f8d3c88a8d3986f2e5344db582c457469a7cb3a0dda953c669cdf9a"
|
||||
name = "github.com/mitchellh/go-server-timing"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "1ca01db910d57d64ec1c68f27105614b77558e28"
|
||||
version = "v1.0.0"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:53bc4cd4914cd7cd52139990d5170d6dc99067ae31c56530621b18b35fc30318"
|
||||
name = "github.com/mitchellh/mapstructure"
|
||||
|
@ -424,17 +325,6 @@
|
|||
revision = "792786c7400a136282c1664665ae0a8db921c6c2"
|
||||
version = "v1.0.0"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:bd9efe4e0b0f768302a1e2f0c22458149278de533e521206e5ddc71848c269a0"
|
||||
name = "github.com/pquerna/cachecontrol"
|
||||
packages = [
|
||||
".",
|
||||
"cacheobject",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "1555304b9b35fdd2b425bccf1a5613677705e7d0"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:c968b29db5d68ec97de404b6d058d5937fa015a141b3b4f7a0d87d5f8226f04c"
|
||||
name = "github.com/prometheus/client_golang"
|
||||
|
@ -503,15 +393,7 @@
|
|||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:cac263b8eb2e9ad2327b70e03be1de1227040bfb3be26b49c4b56cbed568afc7"
|
||||
name = "github.com/xo/dburl"
|
||||
packages = ["."]
|
||||
pruneopts = "UT"
|
||||
revision = "98997a05b24fc069c79fa13b05ccf376c22a326c"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:1a9391a80fe548ffcf90aee8ae35bfb0b188198b57a3fe2ef5bb099ba4b4f610"
|
||||
digest = "1:a84d5ec8b40a827962ea250f2cf03434138ccae9d83fcac12fb49b70c70b80cc"
|
||||
name = "golang.org/x/crypto"
|
||||
packages = [
|
||||
"curve25519",
|
||||
|
@ -519,10 +401,8 @@
|
|||
"ed25519/internal/edwards25519",
|
||||
"internal/chacha20",
|
||||
"internal/subtle",
|
||||
"md4",
|
||||
"nacl/box",
|
||||
"nacl/secretbox",
|
||||
"pbkdf2",
|
||||
"poly1305",
|
||||
"salsa20/salsa",
|
||||
"ssh",
|
||||
|
@ -533,12 +413,11 @@
|
|||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:6b3dbfffba73ea0d8131ecb5738fe87f6addc4c7b73154b9d58e2693ad6a6256"
|
||||
digest = "1:52d140f7ab52e491cc1cbc93e6637aa5e9a7f3beae7545d675b02e52ca9d7290"
|
||||
name = "golang.org/x/net"
|
||||
packages = [
|
||||
"bpf",
|
||||
"context",
|
||||
"context/ctxhttp",
|
||||
"http/httpguts",
|
||||
"http2",
|
||||
"http2/hpack",
|
||||
|
@ -554,17 +433,6 @@
|
|||
pruneopts = "UT"
|
||||
revision = "1da14a5a36f220ea3f03470682b737b1dfd5de22"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:8d1c112fb1679fa097e9a9255a786ee47383fa2549a3da71bcb1334a693ebcfe"
|
||||
name = "golang.org/x/oauth2"
|
||||
packages = [
|
||||
".",
|
||||
"internal",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "0f29369cfe4552d0e4bcddc57cc75f4d7e672a33"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:39ebcc2b11457b703ae9ee2e8cca0f68df21969c6102cb3b705f76cca0ea0239"
|
||||
name = "golang.org/x/sync"
|
||||
|
@ -611,23 +479,6 @@
|
|||
revision = "f21a4dfb5e38f5895301dc265a8def02365cc3d0"
|
||||
version = "v0.3.0"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:7e8b9c5ae49011b12ae8473834ac1a7bb8ac029ba201270c723e4c280c9e4855"
|
||||
name = "google.golang.org/appengine"
|
||||
packages = [
|
||||
"cloudsql",
|
||||
"internal",
|
||||
"internal/base",
|
||||
"internal/datastore",
|
||||
"internal/log",
|
||||
"internal/remote_api",
|
||||
"internal/urlfetch",
|
||||
"urlfetch",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "b2f4a3cf3c67576a2ee09e1fe62656a5086ce880"
|
||||
version = "v1.6.1"
|
||||
|
||||
[[projects]]
|
||||
branch = "master"
|
||||
digest = "1:c3076e7defee87de1236f1814beb588f40a75544c60121e6eb38b3b3721783e2"
|
||||
|
@ -677,26 +528,6 @@
|
|||
revision = "236199dd5f8031d698fb64091194aecd1c3895b2"
|
||||
version = "v1.20.0"
|
||||
|
||||
[[projects]]
|
||||
branch = "v1"
|
||||
digest = "1:6f70106e7bc1c803e8a0a4519e09c12d154771acfa2559206e97b033bbd1dd38"
|
||||
name = "gopkg.in/coreos/go-oidc.v1"
|
||||
packages = ["jose"]
|
||||
pruneopts = "UT"
|
||||
revision = "e860bd55bfa7d7cb35d30d26a167982584f616b0"
|
||||
|
||||
[[projects]]
|
||||
digest = "1:8c05919580be8a5be668709d7e5a69d5cd19b8ee9f23d62ce5b10d3457bf6a13"
|
||||
name = "gopkg.in/square/go-jose.v2"
|
||||
packages = [
|
||||
".",
|
||||
"cipher",
|
||||
"json",
|
||||
]
|
||||
pruneopts = "UT"
|
||||
revision = "730df5f748271903322feb182be83b43ebbbe27d"
|
||||
version = "v2.3.1"
|
||||
|
||||
[[projects]]
|
||||
branch = "altsrc-parse-durations"
|
||||
digest = "1:0370b1bceda03dbfade3abbde639a43f1113bab711ec760452e5c0dcc0c14787"
|
||||
|
@ -745,7 +576,6 @@
|
|||
analyzer-name = "dep"
|
||||
analyzer-version = 1
|
||||
input-imports = [
|
||||
"github.com/DATA-DOG/go-sqlmock",
|
||||
"github.com/cloudflare/brotli-go",
|
||||
"github.com/cloudflare/golibs/lrucache",
|
||||
"github.com/coredns/coredns/core/dnsserver",
|
||||
|
@ -755,27 +585,22 @@
|
|||
"github.com/coredns/coredns/plugin/pkg/dnstest",
|
||||
"github.com/coredns/coredns/plugin/pkg/rcode",
|
||||
"github.com/coredns/coredns/request",
|
||||
"github.com/coreos/go-oidc",
|
||||
"github.com/coreos/go-oidc/jose",
|
||||
"github.com/coreos/go-systemd/daemon",
|
||||
"github.com/creack/pty",
|
||||
"github.com/denisenkom/go-mssqldb",
|
||||
"github.com/elgs/gosqljson",
|
||||
"github.com/equinox-io/equinox",
|
||||
"github.com/facebookgo/grace/gracenet",
|
||||
"github.com/getsentry/raven-go",
|
||||
"github.com/gliderlabs/ssh",
|
||||
"github.com/go-sql-driver/mysql",
|
||||
"github.com/golang-collections/collections/queue",
|
||||
"github.com/google/uuid",
|
||||
"github.com/gorilla/mux",
|
||||
"github.com/gorilla/websocket",
|
||||
"github.com/jmoiron/sqlx",
|
||||
"github.com/kshvakov/clickhouse",
|
||||
"github.com/lib/pq",
|
||||
"github.com/mattn/go-colorable",
|
||||
"github.com/mattn/go-sqlite3",
|
||||
"github.com/miekg/dns",
|
||||
"github.com/mitchellh/go-homedir",
|
||||
"github.com/mitchellh/go-server-timing",
|
||||
"github.com/mitchellh/mapstructure",
|
||||
"github.com/pkg/errors",
|
||||
"github.com/prometheus/client_golang/prometheus",
|
||||
|
@ -784,7 +609,6 @@
|
|||
"github.com/sirupsen/logrus",
|
||||
"github.com/stretchr/testify/assert",
|
||||
"github.com/stretchr/testify/require",
|
||||
"github.com/xo/dburl",
|
||||
"golang.org/x/crypto/nacl/box",
|
||||
"golang.org/x/crypto/ssh",
|
||||
"golang.org/x/crypto/ssh/terminal",
|
||||
|
@ -799,7 +623,6 @@
|
|||
"golang.org/x/sys/windows/svc",
|
||||
"golang.org/x/sys/windows/svc/eventlog",
|
||||
"golang.org/x/sys/windows/svc/mgr",
|
||||
"gopkg.in/coreos/go-oidc.v1/jose",
|
||||
"gopkg.in/urfave/cli.v2",
|
||||
"gopkg.in/urfave/cli.v2/altsrc",
|
||||
"zombiezen.com/go/capnproto2",
|
||||
|
|
38
Gopkg.toml
38
Gopkg.toml
|
@ -6,6 +6,8 @@
|
|||
name = "github.com/cloudflare/brotli-go"
|
||||
unused-packages = false
|
||||
|
||||
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/facebookgo/grace"
|
||||
revision = "75cf19382434e82df4dd84953f566b8ad23d6e9e"
|
||||
|
@ -68,6 +70,10 @@
|
|||
name = "github.com/mholt/caddy"
|
||||
revision = "d3b731e9255b72d4571a5aac125634cf1b6031dc"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/coreos/go-oidc"
|
||||
revision = "a93f71fdfe73d2c0f5413c0565eea0af6523a6df"
|
||||
|
||||
[[constraint]]
|
||||
name = "golang.org/x/crypto"
|
||||
branch = "master" # master required by github.com/miekg/dns
|
||||
|
@ -84,38 +90,6 @@
|
|||
name = "github.com/mitchellh/mapstructure"
|
||||
version = "1.1.2"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/jmoiron/sqlx"
|
||||
version = "1.2.0"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/go-sql-driver/mysql"
|
||||
version = "1.4.1"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/mattn/go-sqlite3"
|
||||
version = "1.11.0"
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/denisenkom/go-mssqldb"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/kshvakov/clickhouse"
|
||||
version = "1.3.9"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/DATA-DOG/go-sqlmock"
|
||||
version = "1.3.3"
|
||||
|
||||
[[constraint]]
|
||||
branch = "master"
|
||||
name = "github.com/xo/dburl"
|
||||
|
||||
[[constraint]]
|
||||
branch = "v2"
|
||||
name = "github.com/coreos/go-oidc"
|
||||
|
||||
[[constraint]]
|
||||
name = "github.com/gliderlabs/ssh"
|
||||
version = "0.2.2"
|
||||
|
|
11
cfsetup.yaml
11
cfsetup.yaml
|
@ -93,14 +93,3 @@ stretch: &stretch
|
|||
- make test
|
||||
|
||||
jessie: *stretch
|
||||
|
||||
# cfsetup compose
|
||||
default-stack: test_dbconnect
|
||||
test_dbconnect:
|
||||
compose:
|
||||
up-args:
|
||||
- --renew-anon-volumes
|
||||
- --abort-on-container-exit
|
||||
- --exit-code-from=cloudflared
|
||||
files:
|
||||
- dbconnect/integration_test/dbconnect.yaml
|
|
@ -14,7 +14,7 @@ import (
|
|||
"github.com/cloudflare/cloudflared/cmd/cloudflared/transfer"
|
||||
"github.com/cloudflare/cloudflared/log"
|
||||
"github.com/cloudflare/cloudflared/origin"
|
||||
"gopkg.in/coreos/go-oidc.v1/jose"
|
||||
"github.com/coreos/go-oidc/jose"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -26,15 +26,15 @@ var logger = log.CreateLogger()
|
|||
type lock struct {
|
||||
lockFilePath string
|
||||
backoff *origin.BackoffHandler
|
||||
sigHandler *signalHandler
|
||||
sigHandler *signalHandler
|
||||
}
|
||||
|
||||
type signalHandler struct {
|
||||
sigChannel chan os.Signal
|
||||
signals []os.Signal
|
||||
sigChannel chan os.Signal
|
||||
signals []os.Signal
|
||||
}
|
||||
|
||||
func (s *signalHandler) register(handler func()) {
|
||||
func (s *signalHandler) register(handler func()){
|
||||
s.sigChannel = make(chan os.Signal, 1)
|
||||
signal.Notify(s.sigChannel, s.signals...)
|
||||
go func(s *signalHandler) {
|
||||
|
@ -59,8 +59,8 @@ func newLock(path string) *lock {
|
|||
return &lock{
|
||||
lockFilePath: lockPath,
|
||||
backoff: &origin.BackoffHandler{MaxRetries: 7},
|
||||
sigHandler: &signalHandler{
|
||||
signals: []os.Signal{syscall.SIGINT, syscall.SIGTERM},
|
||||
sigHandler: &signalHandler{
|
||||
signals: []os.Signal{syscall.SIGINT, syscall.SIGTERM},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
@ -68,8 +68,8 @@ func newLock(path string) *lock {
|
|||
func (l *lock) Acquire() error {
|
||||
// Intercept SIGINT and SIGTERM to release lock before exiting
|
||||
l.sigHandler.register(func() {
|
||||
l.deleteLockFile()
|
||||
os.Exit(0)
|
||||
l.deleteLockFile()
|
||||
os.Exit(0)
|
||||
})
|
||||
|
||||
// Check for a path.lock file
|
||||
|
|
|
@ -7,17 +7,17 @@ import (
|
|||
"net"
|
||||
"net/url"
|
||||
"os"
|
||||
"reflect"
|
||||
"runtime"
|
||||
"runtime/trace"
|
||||
"sync"
|
||||
"syscall"
|
||||
"time"
|
||||
|
||||
"github.com/cloudflare/cloudflared/cmd/cloudflared/buildinfo"
|
||||
"github.com/cloudflare/cloudflared/cmd/cloudflared/config"
|
||||
"github.com/cloudflare/cloudflared/cmd/cloudflared/updater"
|
||||
"github.com/cloudflare/cloudflared/cmd/sqlgateway"
|
||||
"github.com/cloudflare/cloudflared/connection"
|
||||
"github.com/cloudflare/cloudflared/dbconnect"
|
||||
"github.com/cloudflare/cloudflared/hello"
|
||||
"github.com/cloudflare/cloudflared/metrics"
|
||||
"github.com/cloudflare/cloudflared/origin"
|
||||
|
@ -35,6 +35,7 @@ import (
|
|||
"github.com/gliderlabs/ssh"
|
||||
"github.com/google/uuid"
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/crypto/ssh/terminal"
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
"gopkg.in/urfave/cli.v2/altsrc"
|
||||
)
|
||||
|
@ -99,7 +100,43 @@ func Commands() []*cli.Command {
|
|||
ArgsUsage: " ", // can't be the empty string or we get the default output
|
||||
Hidden: false,
|
||||
},
|
||||
dbConnectCmd(),
|
||||
{
|
||||
Name: "db",
|
||||
Action: func(c *cli.Context) error {
|
||||
tags := make(map[string]string)
|
||||
tags["hostname"] = c.String("hostname")
|
||||
raven.SetTagsContext(tags)
|
||||
|
||||
fmt.Printf("\nSQL Database Password: ")
|
||||
pass, err := terminal.ReadPassword(int(syscall.Stdin))
|
||||
if err != nil {
|
||||
logger.Error(err)
|
||||
}
|
||||
|
||||
go sqlgateway.StartProxy(c, logger, string(pass))
|
||||
|
||||
raven.CapturePanic(func() { err = tunnel(c) }, nil)
|
||||
if err != nil {
|
||||
raven.CaptureError(err, nil)
|
||||
}
|
||||
return err
|
||||
},
|
||||
Before: Before,
|
||||
Usage: "SQL Gateway is an SQL over HTTP reverse proxy",
|
||||
Flags: []cli.Flag{
|
||||
&cli.BoolFlag{
|
||||
Name: "db",
|
||||
Value: true,
|
||||
Usage: "Enable the SQL Gateway Proxy",
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Name: "address",
|
||||
Value: "",
|
||||
Usage: "Database connection string: db://user:pass",
|
||||
},
|
||||
},
|
||||
Hidden: true,
|
||||
},
|
||||
}
|
||||
|
||||
var subcommands []*cli.Command
|
||||
|
@ -548,60 +585,6 @@ func addPortIfMissing(uri *url.URL, port int) string {
|
|||
return fmt.Sprintf("%s:%d", uri.Hostname(), port)
|
||||
}
|
||||
|
||||
func dbConnectCmd() *cli.Command {
|
||||
cmd := dbconnect.Cmd()
|
||||
|
||||
// Append the tunnel commands so users can customize the daemon settings.
|
||||
cmd.Flags = appendFlags(Flags(), cmd.Flags...)
|
||||
|
||||
// Override before to run tunnel validation before dbconnect validation.
|
||||
cmd.Before = func(c *cli.Context) error {
|
||||
err := Before(c)
|
||||
if err == nil {
|
||||
err = dbconnect.CmdBefore(c)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
// Override action to setup the Proxy, then if successful, start the tunnel daemon.
|
||||
cmd.Action = func(c *cli.Context) error {
|
||||
err := dbconnect.CmdAction(c)
|
||||
if err == nil {
|
||||
err = tunnel(c)
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
// appendFlags will append extra flags to a slice of flags.
|
||||
//
|
||||
// The cli package will panic if two flags exist with the same name,
|
||||
// so if extraFlags contains a flag that was already defined, modify the
|
||||
// original flags to use the extra version.
|
||||
func appendFlags(flags []cli.Flag, extraFlags ...cli.Flag) []cli.Flag {
|
||||
for _, extra := range extraFlags {
|
||||
var found bool
|
||||
|
||||
// Check if an extra flag overrides an existing flag.
|
||||
for i, flag := range flags {
|
||||
if reflect.DeepEqual(extra.Names(), flag.Names()) {
|
||||
flags[i] = extra
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
// Append the extra flag if it has nothing to override.
|
||||
if !found {
|
||||
flags = append(flags, extra)
|
||||
}
|
||||
}
|
||||
|
||||
return flags
|
||||
}
|
||||
|
||||
func tunnelFlags(shouldHide bool) []cli.Flag {
|
||||
return []cli.Flag{
|
||||
&cli.StringFlag{
|
||||
|
|
|
@ -0,0 +1,148 @@
|
|||
package sqlgateway
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
_ "github.com/lib/pq"
|
||||
cli "gopkg.in/urfave/cli.v2"
|
||||
|
||||
"github.com/elgs/gosqljson"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/sirupsen/logrus"
|
||||
)
|
||||
|
||||
type Message struct {
|
||||
Connection Connection `json:"connection"`
|
||||
Command string `json:"command"`
|
||||
Params []interface{} `json:"params"`
|
||||
}
|
||||
|
||||
type Connection struct {
|
||||
SSLMode string `json:"sslmode"`
|
||||
Token string `json:"token"`
|
||||
}
|
||||
|
||||
type Response struct {
|
||||
Columns []string `json:"columns"`
|
||||
Rows [][]string `json:"rows"`
|
||||
Error string `json:"error"`
|
||||
}
|
||||
|
||||
type Proxy struct {
|
||||
Context *cli.Context
|
||||
Router *mux.Router
|
||||
Token string
|
||||
User string
|
||||
Password string
|
||||
Driver string
|
||||
Database string
|
||||
Logger *logrus.Logger
|
||||
}
|
||||
|
||||
func StartProxy(c *cli.Context, logger *logrus.Logger, password string) error {
|
||||
proxy := NewProxy(c, logger, password)
|
||||
|
||||
logger.Infof("Starting SQL Gateway Proxy on port %s", strings.Split(c.String("url"), ":")[1])
|
||||
|
||||
err := http.ListenAndServe(":"+strings.Split(c.String("url"), ":")[1], proxy.Router)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func randID(n int, c *cli.Context) string {
|
||||
charBytes := []byte("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890")
|
||||
b := make([]byte, n)
|
||||
for i := range b {
|
||||
b[i] = charBytes[rand.Intn(len(charBytes))]
|
||||
}
|
||||
return fmt.Sprintf("%s&%s", c.String("hostname"), b)
|
||||
}
|
||||
|
||||
// db://user@dbname
|
||||
func parseInfo(input string) (string, string, string) {
|
||||
p1 := strings.Split(input, "://")
|
||||
p2 := strings.Split(p1[1], "@")
|
||||
return p1[0], p2[0], p2[1]
|
||||
}
|
||||
|
||||
func NewProxy(c *cli.Context, logger *logrus.Logger, pass string) *Proxy {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
driver, user, dbname := parseInfo(c.String("address"))
|
||||
proxy := Proxy{
|
||||
Context: c,
|
||||
Router: mux.NewRouter(),
|
||||
Token: randID(64, c),
|
||||
Logger: logger,
|
||||
User: user,
|
||||
Password: pass,
|
||||
Database: dbname,
|
||||
Driver: driver,
|
||||
}
|
||||
|
||||
logger.Info(fmt.Sprintf(`
|
||||
|
||||
--------------------
|
||||
SQL Gateway Proxy
|
||||
Token: %s
|
||||
--------------------
|
||||
|
||||
`, proxy.Token))
|
||||
|
||||
proxy.Router.HandleFunc("/", proxy.proxyRequest).Methods("POST")
|
||||
return &proxy
|
||||
}
|
||||
|
||||
func (proxy *Proxy) proxyRequest(rw http.ResponseWriter, req *http.Request) {
|
||||
var message Message
|
||||
response := Response{}
|
||||
|
||||
err := json.NewDecoder(req.Body).Decode(&message)
|
||||
if err != nil {
|
||||
proxy.Logger.Error(err)
|
||||
http.Error(rw, fmt.Sprintf("400 - %s", err.Error()), http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
if message.Connection.Token != proxy.Token {
|
||||
proxy.Logger.Error("Invalid token")
|
||||
http.Error(rw, "400 - Invalid token", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
|
||||
connStr := fmt.Sprintf("user=%s password=%s dbname=%s sslmode=%s", proxy.User, proxy.Password, proxy.Database, message.Connection.SSLMode)
|
||||
|
||||
db, err := sql.Open(proxy.Driver, connStr)
|
||||
defer db.Close()
|
||||
|
||||
if err != nil {
|
||||
proxy.Logger.Error(err)
|
||||
http.Error(rw, fmt.Sprintf("400 - %s", err.Error()), http.StatusBadRequest)
|
||||
return
|
||||
|
||||
} else {
|
||||
proxy.Logger.Info("Forwarding SQL: ", message.Command)
|
||||
rw.Header().Set("Content-Type", "application/json")
|
||||
|
||||
headers, data, err := gosqljson.QueryDbToArray(db, "lower", message.Command, message.Params...)
|
||||
|
||||
if err != nil {
|
||||
proxy.Logger.Error(err)
|
||||
http.Error(rw, fmt.Sprintf("400 - %s", err.Error()), http.StatusBadRequest)
|
||||
return
|
||||
|
||||
} else {
|
||||
response = Response{headers, data, ""}
|
||||
}
|
||||
}
|
||||
json.NewEncoder(rw).Encode(response)
|
||||
}
|
|
@ -1,145 +0,0 @@
|
|||
package dbconnect
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
"time"
|
||||
"unicode"
|
||||
"unicode/utf8"
|
||||
)
|
||||
|
||||
// Client is an interface to talk to any database.
|
||||
//
|
||||
// Currently, the only implementation is SQLClient, but its structure
|
||||
// should be designed to handle a MongoClient or RedisClient in the future.
|
||||
type Client interface {
|
||||
Ping(context.Context) error
|
||||
Submit(context.Context, *Command) (interface{}, error)
|
||||
}
|
||||
|
||||
// NewClient creates a database client based on its URL scheme.
|
||||
func NewClient(ctx context.Context, originURL *url.URL) (Client, error) {
|
||||
return NewSQLClient(ctx, originURL)
|
||||
}
|
||||
|
||||
// Command is a standard, non-vendor format for submitting database commands.
|
||||
//
|
||||
// When determining the scope of this struct, refer to the following litmus test:
|
||||
// Could this (roughly) conform to SQL, Document-based, and Key-value command formats?
|
||||
type Command struct {
|
||||
Statement string `json:"statement"`
|
||||
Arguments Arguments `json:"arguments,omitempty"`
|
||||
Mode string `json:"mode,omitempty"`
|
||||
Isolation string `json:"isolation,omitempty"`
|
||||
Timeout time.Duration `json:"timeout,omitempty"`
|
||||
}
|
||||
|
||||
// Validate enforces the contract of Command: non empty statement (both in length and logic),
|
||||
// lowercase mode and isolation, non-zero timeout, and valid Arguments.
|
||||
func (cmd *Command) Validate() error {
|
||||
if cmd.Statement == "" {
|
||||
return fmt.Errorf("cannot provide an empty statement")
|
||||
}
|
||||
|
||||
if strings.Map(func(char rune) rune {
|
||||
if char == ';' || unicode.IsSpace(char) {
|
||||
return -1
|
||||
}
|
||||
return char
|
||||
}, cmd.Statement) == "" {
|
||||
return fmt.Errorf("cannot provide a statement with no logic: '%s'", cmd.Statement)
|
||||
}
|
||||
|
||||
cmd.Mode = strings.ToLower(cmd.Mode)
|
||||
cmd.Isolation = strings.ToLower(cmd.Isolation)
|
||||
|
||||
if cmd.Timeout.Nanoseconds() <= 0 {
|
||||
cmd.Timeout = 24 * time.Hour
|
||||
}
|
||||
|
||||
return cmd.Arguments.Validate()
|
||||
}
|
||||
|
||||
// UnmarshalJSON converts a byte representation of JSON into a Command, which is also validated.
|
||||
func (cmd *Command) UnmarshalJSON(data []byte) error {
|
||||
// Alias is required to avoid infinite recursion from the default UnmarshalJSON.
|
||||
type Alias Command
|
||||
alias := &struct {
|
||||
*Alias
|
||||
}{
|
||||
Alias: (*Alias)(cmd),
|
||||
}
|
||||
|
||||
err := json.Unmarshal(data, &alias)
|
||||
if err == nil {
|
||||
err = cmd.Validate()
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// Arguments is a wrapper for either map-based or array-based Command arguments.
|
||||
//
|
||||
// Each field is mutually-exclusive and some Client implementations may not
|
||||
// support both fields (eg. MySQL does not accept named arguments).
|
||||
type Arguments struct {
|
||||
Named map[string]interface{}
|
||||
Positional []interface{}
|
||||
}
|
||||
|
||||
// Validate enforces the contract of Arguments: non nil, mutually exclusive, and no empty or reserved keys.
|
||||
func (args *Arguments) Validate() error {
|
||||
if args.Named == nil {
|
||||
args.Named = map[string]interface{}{}
|
||||
}
|
||||
if args.Positional == nil {
|
||||
args.Positional = []interface{}{}
|
||||
}
|
||||
|
||||
if len(args.Named) > 0 && len(args.Positional) > 0 {
|
||||
return fmt.Errorf("both named and positional arguments cannot be specified: %+v and %+v", args.Named, args.Positional)
|
||||
}
|
||||
|
||||
for key := range args.Named {
|
||||
if key == "" {
|
||||
return fmt.Errorf("named arguments cannot contain an empty key: %+v", args.Named)
|
||||
}
|
||||
if !utf8.ValidString(key) {
|
||||
return fmt.Errorf("named argument does not conform to UTF-8 encoding: %s", key)
|
||||
}
|
||||
if strings.HasPrefix(key, "_") {
|
||||
return fmt.Errorf("named argument cannot start with a reserved keyword '_': %s", key)
|
||||
}
|
||||
if unicode.IsNumber([]rune(key)[0]) {
|
||||
return fmt.Errorf("named argument cannot start with a number: %s", key)
|
||||
}
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// UnmarshalJSON converts a byte representation of JSON into Arguments, which is also validated.
|
||||
func (args *Arguments) UnmarshalJSON(data []byte) error {
|
||||
var obj interface{}
|
||||
err := json.Unmarshal(data, &obj)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
named, ok := obj.(map[string]interface{})
|
||||
if ok {
|
||||
args.Named = named
|
||||
} else {
|
||||
positional, ok := obj.([]interface{})
|
||||
if ok {
|
||||
args.Positional = positional
|
||||
} else {
|
||||
return fmt.Errorf("arguments must either be an object {\"0\":\"val\"} or an array [\"val\"]: %s", string(data))
|
||||
}
|
||||
}
|
||||
|
||||
return args.Validate()
|
||||
}
|
|
@ -1,183 +0,0 @@
|
|||
package dbconnect
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestCommandValidateEmpty(t *testing.T) {
|
||||
stmts := []string{
|
||||
"",
|
||||
";",
|
||||
" \n\t",
|
||||
";\n;\t;",
|
||||
}
|
||||
|
||||
for _, stmt := range stmts {
|
||||
cmd := Command{Statement: stmt}
|
||||
|
||||
assert.Error(t, cmd.Validate(), stmt)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCommandValidateMode(t *testing.T) {
|
||||
modes := []string{
|
||||
"",
|
||||
"query",
|
||||
"ExEc",
|
||||
"PREPARE",
|
||||
}
|
||||
|
||||
for _, mode := range modes {
|
||||
cmd := Command{Statement: "Ok", Mode: mode}
|
||||
|
||||
assert.NoError(t, cmd.Validate(), mode)
|
||||
assert.Equal(t, strings.ToLower(mode), cmd.Mode)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCommandValidateIsolation(t *testing.T) {
|
||||
isos := []string{
|
||||
"",
|
||||
"default",
|
||||
"read_committed",
|
||||
"SNAPshot",
|
||||
}
|
||||
|
||||
for _, iso := range isos {
|
||||
cmd := Command{Statement: "Ok", Isolation: iso}
|
||||
|
||||
assert.NoError(t, cmd.Validate(), iso)
|
||||
assert.Equal(t, strings.ToLower(iso), cmd.Isolation)
|
||||
}
|
||||
}
|
||||
|
||||
func TestCommandValidateTimeout(t *testing.T) {
|
||||
cmd := Command{Statement: "Ok", Timeout: 0}
|
||||
|
||||
assert.NoError(t, cmd.Validate())
|
||||
assert.NotZero(t, cmd.Timeout)
|
||||
|
||||
cmd = Command{Statement: "Ok", Timeout: 1 * time.Second}
|
||||
|
||||
assert.NoError(t, cmd.Validate())
|
||||
assert.Equal(t, 1*time.Second, cmd.Timeout)
|
||||
}
|
||||
|
||||
func TestCommandValidateArguments(t *testing.T) {
|
||||
cmd := Command{Statement: "Ok", Arguments: Arguments{
|
||||
Named: map[string]interface{}{"key": "val"},
|
||||
Positional: []interface{}{"val"},
|
||||
}}
|
||||
|
||||
assert.Error(t, cmd.Validate())
|
||||
}
|
||||
|
||||
func TestCommandUnmarshalJSON(t *testing.T) {
|
||||
strs := []string{
|
||||
"{\"statement\":\"Ok\"}",
|
||||
"{\"statement\":\"Ok\",\"arguments\":[0, 3.14, \"apple\"],\"mode\":\"query\"}",
|
||||
"{\"statement\":\"Ok\",\"isolation\":\"read_uncommitted\",\"timeout\":1000}",
|
||||
}
|
||||
|
||||
for _, str := range strs {
|
||||
var cmd Command
|
||||
assert.NoError(t, json.Unmarshal([]byte(str), &cmd), str)
|
||||
}
|
||||
|
||||
strs = []string{
|
||||
"",
|
||||
"\"",
|
||||
"{}",
|
||||
"{\"argument\":{\"key\":\"val\"}}",
|
||||
"{\"statement\":[\"Ok\"]}",
|
||||
}
|
||||
|
||||
for _, str := range strs {
|
||||
var cmd Command
|
||||
assert.Error(t, json.Unmarshal([]byte(str), &cmd), str)
|
||||
}
|
||||
}
|
||||
|
||||
func TestArgumentsValidateNotNil(t *testing.T) {
|
||||
args := Arguments{}
|
||||
|
||||
assert.NoError(t, args.Validate())
|
||||
assert.NotNil(t, args.Named)
|
||||
assert.NotNil(t, args.Positional)
|
||||
}
|
||||
|
||||
func TestArgumentsValidateMutuallyExclusive(t *testing.T) {
|
||||
args := []Arguments{
|
||||
Arguments{},
|
||||
Arguments{Named: map[string]interface{}{"key": "val"}},
|
||||
Arguments{Positional: []interface{}{"val"}},
|
||||
}
|
||||
|
||||
for _, arg := range args {
|
||||
assert.NoError(t, arg.Validate())
|
||||
assert.False(t, len(arg.Named) > 0 && len(arg.Positional) > 0)
|
||||
}
|
||||
|
||||
args = []Arguments{
|
||||
Arguments{
|
||||
Named: map[string]interface{}{"key": "val"},
|
||||
Positional: []interface{}{"val"},
|
||||
},
|
||||
}
|
||||
|
||||
for _, arg := range args {
|
||||
assert.Error(t, arg.Validate())
|
||||
assert.True(t, len(arg.Named) > 0 && len(arg.Positional) > 0)
|
||||
}
|
||||
}
|
||||
|
||||
func TestArgumentsValidateKeys(t *testing.T) {
|
||||
keys := []string{
|
||||
"",
|
||||
"_",
|
||||
"_key",
|
||||
"1",
|
||||
"1key",
|
||||
"\xf0\x28\x8c\xbc", // non-utf8
|
||||
}
|
||||
|
||||
for _, key := range keys {
|
||||
args := Arguments{Named: map[string]interface{}{key: "val"}}
|
||||
|
||||
assert.Error(t, args.Validate(), key)
|
||||
}
|
||||
}
|
||||
|
||||
func TestArgumentsUnmarshalJSON(t *testing.T) {
|
||||
strs := []string{
|
||||
"{}",
|
||||
"{\"key\":\"val\"}",
|
||||
"{\"key\":[1, 3.14, {\"key\":\"val\"}]}",
|
||||
"[]",
|
||||
"[\"key\",\"val\"]",
|
||||
"[{}]",
|
||||
}
|
||||
|
||||
for _, str := range strs {
|
||||
var args Arguments
|
||||
assert.NoError(t, json.Unmarshal([]byte(str), &args), str)
|
||||
}
|
||||
|
||||
strs = []string{
|
||||
"",
|
||||
"\"",
|
||||
"1",
|
||||
"\"key\"",
|
||||
"{\"key\",\"val\"}",
|
||||
}
|
||||
|
||||
for _, str := range strs {
|
||||
var args Arguments
|
||||
assert.Error(t, json.Unmarshal([]byte(str), &args), str)
|
||||
}
|
||||
}
|
157
dbconnect/cmd.go
157
dbconnect/cmd.go
|
@ -1,157 +0,0 @@
|
|||
package dbconnect
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"net"
|
||||
"strconv"
|
||||
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
"gopkg.in/urfave/cli.v2/altsrc"
|
||||
)
|
||||
|
||||
// Cmd is the entrypoint command for dbconnect.
|
||||
//
|
||||
// The tunnel package is responsible for appending this to tunnel.Commands().
|
||||
func Cmd() *cli.Command {
|
||||
return &cli.Command{
|
||||
Category: "Database Connect (ALPHA)",
|
||||
Name: "db-connect",
|
||||
Usage: "Access your SQL database from Cloudflare Workers or the browser",
|
||||
ArgsUsage: " ",
|
||||
Description: `
|
||||
Creates a connection between your database and the Cloudflare edge.
|
||||
Now you can execute SQL commands anywhere you can send HTTPS requests.
|
||||
|
||||
Connect your database with any of the following commands, you can also try the "playground" without a database:
|
||||
|
||||
cloudflared db-connect --hostname sql.mysite.com --url postgres://user:pass@localhost?sslmode=disable \
|
||||
--auth-domain mysite.cloudflareaccess.com --application-aud my-access-policy-tag
|
||||
cloudflared db-connect --hostname sql-dev.mysite.com --url mysql://localhost --insecure
|
||||
cloudflared db-connect --playground
|
||||
|
||||
Requests should be authenticated using Cloudflare Access, learn more about how to enable it here:
|
||||
|
||||
https://developers.cloudflare.com/access/service-auth/service-token/
|
||||
`,
|
||||
Flags: []cli.Flag{
|
||||
altsrc.NewStringFlag(&cli.StringFlag{
|
||||
Name: "url",
|
||||
Usage: "URL to the database (eg. postgres://user:pass@localhost?sslmode=disable)",
|
||||
EnvVars: []string{"TUNNEL_URL"},
|
||||
}),
|
||||
altsrc.NewStringFlag(&cli.StringFlag{
|
||||
Name: "hostname",
|
||||
Usage: "Hostname to accept commands over HTTPS (eg. sql.mysite.com)",
|
||||
EnvVars: []string{"TUNNEL_HOSTNAME"},
|
||||
}),
|
||||
altsrc.NewStringFlag(&cli.StringFlag{
|
||||
Name: "auth-domain",
|
||||
Usage: "Cloudflare Access authentication domain for your account (eg. mysite.cloudflareaccess.com)",
|
||||
EnvVars: []string{"TUNNEL_ACCESS_AUTH_DOMAIN"},
|
||||
}),
|
||||
altsrc.NewStringFlag(&cli.StringFlag{
|
||||
Name: "application-aud",
|
||||
Usage: "Cloudflare Access application \"AUD\" to verify JWTs from requests",
|
||||
EnvVars: []string{"TUNNEL_ACCESS_APPLICATION_AUD"},
|
||||
}),
|
||||
altsrc.NewBoolFlag(&cli.BoolFlag{
|
||||
Name: "insecure",
|
||||
Usage: "Disable authentication, the database will be open to the Internet",
|
||||
Value: false,
|
||||
EnvVars: []string{"TUNNEL_ACCESS_INSECURE"},
|
||||
}),
|
||||
altsrc.NewBoolFlag(&cli.BoolFlag{
|
||||
Name: "playground",
|
||||
Usage: "Run a temporary, in-memory SQLite3 database for testing",
|
||||
Value: false,
|
||||
EnvVars: []string{"TUNNEL_HELLO_WORLD"},
|
||||
}),
|
||||
altsrc.NewStringFlag(&cli.StringFlag{
|
||||
Name: "loglevel",
|
||||
Value: "debug", // Make it more verbose than the tunnel default 'info'.
|
||||
EnvVars: []string{"TUNNEL_LOGLEVEL"},
|
||||
Hidden: true,
|
||||
}),
|
||||
},
|
||||
Before: CmdBefore,
|
||||
Action: CmdAction,
|
||||
Hidden: true,
|
||||
}
|
||||
}
|
||||
|
||||
// CmdBefore runs some validation checks before running the command.
|
||||
func CmdBefore(c *cli.Context) error {
|
||||
// Show the help text is no flags are specified.
|
||||
if c.NumFlags() == 0 {
|
||||
return cli.ShowSubcommandHelp(c)
|
||||
}
|
||||
|
||||
// Hello-world and playground are synonymous with each other,
|
||||
// unset hello-world to prevent tunnel from initializing the hello package.
|
||||
if c.IsSet("hello-world") {
|
||||
c.Set("playground", "true")
|
||||
c.Set("hello-world", "false")
|
||||
}
|
||||
|
||||
// Unix-socket database urls are supported, but the logic is the same as url.
|
||||
if c.IsSet("unix-socket") {
|
||||
c.Set("url", c.String("unix-socket"))
|
||||
c.Set("unix-socket", "")
|
||||
}
|
||||
|
||||
// When playground mode is enabled, run with an in-memory database.
|
||||
if c.IsSet("playground") {
|
||||
c.Set("url", "sqlite3::memory:?cache=shared")
|
||||
c.Set("insecure", strconv.FormatBool(!c.IsSet("auth-domain") && !c.IsSet("application-aud")))
|
||||
}
|
||||
|
||||
// At this point, insecure configurations are valid.
|
||||
if c.Bool("insecure") {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Ensure that secure configurations specify a hostname, domain, and tag for JWT validation.
|
||||
if !c.IsSet("hostname") || !c.IsSet("auth-domain") || !c.IsSet("application-aud") {
|
||||
log.Fatal("must specify --hostname, --auth-domain, and --application-aud unless you want to run in --insecure mode")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// CmdAction starts the Proxy and sets the url in cli.Context to point to the Proxy address.
|
||||
func CmdAction(c *cli.Context) error {
|
||||
// STOR-612: sync with context in tunnel daemon.
|
||||
ctx := context.Background()
|
||||
|
||||
var proxy *Proxy
|
||||
var err error
|
||||
if c.Bool("insecure") {
|
||||
proxy, err = NewInsecureProxy(ctx, c.String("url"))
|
||||
} else {
|
||||
proxy, err = NewSecureProxy(ctx, c.String("url"), c.String("auth-domain"), c.String("application-aud"))
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
return err
|
||||
}
|
||||
|
||||
listenerC := make(chan net.Listener)
|
||||
defer close(listenerC)
|
||||
|
||||
// Since the Proxy should only talk to the tunnel daemon, find the next available
|
||||
// localhost port and start to listen to requests.
|
||||
go func() {
|
||||
err := proxy.Start(ctx, "127.0.0.1:", listenerC)
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}()
|
||||
|
||||
// Block until the the Proxy is online, retreive its address, and change the url to point to it.
|
||||
// This is effectively "handing over" control to the tunnel package so it can run the tunnel daemon.
|
||||
c.Set("url", "https://"+(<-listenerC).Addr().String())
|
||||
|
||||
return nil
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package dbconnect
|
||||
|
||||
import (
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"gopkg.in/urfave/cli.v2"
|
||||
)
|
||||
|
||||
func TestCmd(t *testing.T) {
|
||||
tests := [][]string{
|
||||
{"cloudflared", "db-connect", "--playground"},
|
||||
{"cloudflared", "db-connect", "--playground", "--hostname", "sql.mysite.com"},
|
||||
{"cloudflared", "db-connect", "--url", "sqlite3::memory:?cache=shared", "--insecure"},
|
||||
{"cloudflared", "db-connect", "--url", "sqlite3::memory:?cache=shared", "--hostname", "sql.mysite.com", "--auth-domain", "mysite.cloudflareaccess.com", "--application-aud", "aud"},
|
||||
}
|
||||
|
||||
app := &cli.App{
|
||||
Name: "cloudflared",
|
||||
Commands: []*cli.Command{Cmd()},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
assert.NoError(t, app.Run(test))
|
||||
}
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
# docker-compose -f ./dbconnect/integration_test/dbconnect.yaml up --build --force-recreate --renew-anon-volumes --exit-code-from cloudflared
|
||||
|
||||
version: "2.3"
|
||||
networks:
|
||||
test-dbconnect-network:
|
||||
driver: bridge
|
||||
services:
|
||||
cloudflared:
|
||||
build:
|
||||
context: ../../
|
||||
dockerfile: dev.Dockerfile
|
||||
command: go test github.com/cloudflare/cloudflared/dbconnect/integration_test -v
|
||||
depends_on:
|
||||
postgres:
|
||||
condition: service_healthy
|
||||
mysql:
|
||||
condition: service_healthy
|
||||
mssql:
|
||||
condition: service_healthy
|
||||
clickhouse:
|
||||
condition: service_healthy
|
||||
environment:
|
||||
DBCONNECT_INTEGRATION_TEST: "true"
|
||||
POSTGRESQL_URL: postgres://postgres:secret@postgres/db?sslmode=disable
|
||||
MYSQL_URL: mysql://root:secret@mysql/db?tls=false
|
||||
MSSQL_URL: mssql://sa:secret12345!@mssql
|
||||
CLICKHOUSE_URL: clickhouse://clickhouse:9000/db
|
||||
networks:
|
||||
- test-dbconnect-network
|
||||
postgres:
|
||||
image: postgres:11.4-alpine
|
||||
environment:
|
||||
POSTGRES_DB: db
|
||||
POSTGRES_PASSWORD: secret
|
||||
healthcheck:
|
||||
test: ["CMD", "pg_isready", "-U", "postgres"]
|
||||
start_period: 3s
|
||||
interval: 1s
|
||||
timeout: 3s
|
||||
retries: 10
|
||||
networks:
|
||||
- test-dbconnect-network
|
||||
mysql:
|
||||
image: mysql:8.0
|
||||
environment:
|
||||
MYSQL_DATABASE: db
|
||||
MYSQL_ROOT_PASSWORD: secret
|
||||
healthcheck:
|
||||
test: ["CMD", "mysqladmin", "ping"]
|
||||
start_period: 3s
|
||||
interval: 1s
|
||||
timeout: 3s
|
||||
retries: 10
|
||||
networks:
|
||||
- test-dbconnect-network
|
||||
mssql:
|
||||
image: mcr.microsoft.com/mssql/server:2017-CU8-ubuntu
|
||||
environment:
|
||||
ACCEPT_EULA: "Y"
|
||||
SA_PASSWORD: secret12345!
|
||||
healthcheck:
|
||||
test: ["CMD", "/opt/mssql-tools/bin/sqlcmd", "-S", "localhost", "-U", "sa", "-P", "secret12345!", "-Q", "SELECT 1"]
|
||||
start_period: 3s
|
||||
interval: 1s
|
||||
timeout: 3s
|
||||
retries: 10
|
||||
networks:
|
||||
- test-dbconnect-network
|
||||
clickhouse:
|
||||
image: yandex/clickhouse-server:19.11
|
||||
healthcheck:
|
||||
test: ["CMD", "clickhouse-client", "--query", "SELECT 1"]
|
||||
start_period: 3s
|
||||
interval: 1s
|
||||
timeout: 3s
|
||||
retries: 10
|
||||
networks:
|
||||
- test-dbconnect-network
|
|
@ -1,265 +0,0 @@
|
|||
package dbconnect_test
|
||||
|
||||
import (
|
||||
"context"
|
||||
"log"
|
||||
"net/url"
|
||||
"os"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
|
||||
"github.com/cloudflare/cloudflared/dbconnect"
|
||||
)
|
||||
|
||||
func TestIntegrationPostgreSQL(t *testing.T) {
|
||||
ctx, pq := helperNewSQLClient(t, "POSTGRESQL_URL")
|
||||
|
||||
err := pq.Ping(ctx)
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, err = pq.Submit(ctx, &dbconnect.Command{
|
||||
Statement: "CREATE TABLE t (a TEXT, b UUID, c JSON, d INET[], e SERIAL);",
|
||||
Mode: "exec",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, err = pq.Submit(ctx, &dbconnect.Command{
|
||||
Statement: "INSERT INTO t VALUES ($1, $2, $3, $4);",
|
||||
Mode: "exec",
|
||||
Arguments: dbconnect.Arguments{
|
||||
Positional: []interface{}{
|
||||
"text",
|
||||
"6b8d686d-bd8e-43bc-b09a-cfcbbe702c10",
|
||||
"{\"bool\":true,\"array\":[\"a\", 1, 3.14],\"embed\":{\"num\":21}}",
|
||||
[]string{"1.1.1.1", "1.0.0.1"},
|
||||
},
|
||||
},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, err = pq.Submit(ctx, &dbconnect.Command{
|
||||
Statement: "UPDATE t SET b = NULL;",
|
||||
Mode: "exec",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
res, err := pq.Submit(ctx, &dbconnect.Command{
|
||||
Statement: "SELECT * FROM t;",
|
||||
Mode: "query",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.IsType(t, make([]map[string]interface{}, 0), res)
|
||||
|
||||
actual := res.([]map[string]interface{})[0]
|
||||
expected := map[string]interface{}{
|
||||
"a": "text",
|
||||
"b": nil,
|
||||
"c": map[string]interface{}{
|
||||
"bool": true,
|
||||
"array": []interface{}{"a", float64(1), 3.14},
|
||||
"embed": map[string]interface{}{"num": float64(21)},
|
||||
},
|
||||
"d": "{1.1.1.1,1.0.0.1}",
|
||||
"e": int64(1),
|
||||
}
|
||||
assert.EqualValues(t, expected, actual)
|
||||
|
||||
_, err = pq.Submit(ctx, &dbconnect.Command{
|
||||
Statement: "DROP TABLE t;",
|
||||
Mode: "exec",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestIntegrationMySQL(t *testing.T) {
|
||||
ctx, my := helperNewSQLClient(t, "MYSQL_URL")
|
||||
|
||||
err := my.Ping(ctx)
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, err = my.Submit(ctx, &dbconnect.Command{
|
||||
Statement: "CREATE TABLE t (a CHAR, b TINYINT, c FLOAT, d JSON, e YEAR);",
|
||||
Mode: "exec",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, err = my.Submit(ctx, &dbconnect.Command{
|
||||
Statement: "INSERT INTO t VALUES (?, ?, ?, ?, ?);",
|
||||
Mode: "exec",
|
||||
Arguments: dbconnect.Arguments{
|
||||
Positional: []interface{}{
|
||||
"a",
|
||||
10,
|
||||
3.14,
|
||||
"{\"bool\":true}",
|
||||
2000,
|
||||
},
|
||||
},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, err = my.Submit(ctx, &dbconnect.Command{
|
||||
Statement: "ALTER TABLE t ADD COLUMN f GEOMETRY;",
|
||||
Mode: "exec",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
res, err := my.Submit(ctx, &dbconnect.Command{
|
||||
Statement: "SELECT * FROM t;",
|
||||
Mode: "query",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.IsType(t, make([]map[string]interface{}, 0), res)
|
||||
|
||||
actual := res.([]map[string]interface{})[0]
|
||||
expected := map[string]interface{}{
|
||||
"a": "a",
|
||||
"b": float64(10),
|
||||
"c": 3.14,
|
||||
"d": map[string]interface{}{"bool": true},
|
||||
"e": float64(2000),
|
||||
"f": nil,
|
||||
}
|
||||
assert.EqualValues(t, expected, actual)
|
||||
|
||||
_, err = my.Submit(ctx, &dbconnect.Command{
|
||||
Statement: "DROP TABLE t;",
|
||||
Mode: "exec",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestIntegrationMSSQL(t *testing.T) {
|
||||
ctx, ms := helperNewSQLClient(t, "MSSQL_URL")
|
||||
|
||||
err := ms.Ping(ctx)
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, err = ms.Submit(ctx, &dbconnect.Command{
|
||||
Statement: "CREATE TABLE t (a BIT, b DECIMAL, c MONEY, d TEXT);",
|
||||
Mode: "exec"})
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, err = ms.Submit(ctx, &dbconnect.Command{
|
||||
Statement: "INSERT INTO t VALUES (?, ?, ?, ?);",
|
||||
Mode: "exec",
|
||||
Arguments: dbconnect.Arguments{
|
||||
Positional: []interface{}{
|
||||
0,
|
||||
3,
|
||||
"$0.99",
|
||||
"text",
|
||||
},
|
||||
},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, err = ms.Submit(ctx, &dbconnect.Command{
|
||||
Statement: "UPDATE t SET d = NULL;",
|
||||
Mode: "exec",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
res, err := ms.Submit(ctx, &dbconnect.Command{
|
||||
Statement: "SELECT * FROM t;",
|
||||
Mode: "query",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.IsType(t, make([]map[string]interface{}, 0), res)
|
||||
|
||||
actual := res.([]map[string]interface{})[0]
|
||||
expected := map[string]interface{}{
|
||||
"a": false,
|
||||
"b": float64(3),
|
||||
"c": float64(0.99),
|
||||
"d": nil,
|
||||
}
|
||||
assert.EqualValues(t, expected, actual)
|
||||
|
||||
_, err = ms.Submit(ctx, &dbconnect.Command{
|
||||
Statement: "DROP TABLE t;",
|
||||
Mode: "exec",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestIntegrationClickhouse(t *testing.T) {
|
||||
ctx, ch := helperNewSQLClient(t, "CLICKHOUSE_URL")
|
||||
|
||||
err := ch.Ping(ctx)
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, err = ch.Submit(ctx, &dbconnect.Command{
|
||||
Statement: "CREATE TABLE t (a UUID, b String, c Float64, d UInt32, e Int16, f Array(Enum8('a'=1, 'b'=2, 'c'=3))) engine=Memory;",
|
||||
Mode: "exec",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
_, err = ch.Submit(ctx, &dbconnect.Command{
|
||||
Statement: "INSERT INTO t VALUES (?, ?, ?, ?, ?, ?);",
|
||||
Mode: "exec",
|
||||
Arguments: dbconnect.Arguments{
|
||||
Positional: []interface{}{
|
||||
"ec65f626-6f50-4c86-9628-6314ef1edacd",
|
||||
"",
|
||||
3.14,
|
||||
314,
|
||||
-144,
|
||||
[]string{"a", "b", "c"},
|
||||
},
|
||||
},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
|
||||
res, err := ch.Submit(ctx, &dbconnect.Command{
|
||||
Statement: "SELECT * FROM t;",
|
||||
Mode: "query",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.IsType(t, make([]map[string]interface{}, 0), res)
|
||||
|
||||
actual := res.([]map[string]interface{})[0]
|
||||
expected := map[string]interface{}{
|
||||
"a": "ec65f626-6f50-4c86-9628-6314ef1edacd",
|
||||
"b": "",
|
||||
"c": float64(3.14),
|
||||
"d": uint32(314),
|
||||
"e": int16(-144),
|
||||
"f": []string{"a", "b", "c"},
|
||||
}
|
||||
assert.EqualValues(t, expected, actual)
|
||||
|
||||
_, err = ch.Submit(ctx, &dbconnect.Command{
|
||||
Statement: "DROP TABLE t;",
|
||||
Mode: "exec",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func helperNewSQLClient(t *testing.T, env string) (context.Context, dbconnect.Client) {
|
||||
_, ok := os.LookupEnv("DBCONNECT_INTEGRATION_TEST")
|
||||
if ok {
|
||||
t.Helper()
|
||||
} else {
|
||||
t.SkipNow()
|
||||
}
|
||||
|
||||
val, ok := os.LookupEnv(env)
|
||||
if !ok {
|
||||
log.Fatalf("must provide database url as environment variable: %s", env)
|
||||
}
|
||||
|
||||
parsed, err := url.Parse(val)
|
||||
if err != nil {
|
||||
log.Fatalf("cannot provide invalid database url: %s=%s", env, val)
|
||||
}
|
||||
|
||||
ctx := context.Background()
|
||||
client, err := dbconnect.NewSQLClient(ctx, parsed)
|
||||
if err != nil {
|
||||
log.Fatalf("could not start test client: %s", err)
|
||||
}
|
||||
|
||||
return ctx, client
|
||||
}
|
|
@ -1,274 +0,0 @@
|
|||
package dbconnect
|
||||
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"io"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"time"
|
||||
|
||||
"github.com/cloudflare/cloudflared/hello"
|
||||
"github.com/cloudflare/cloudflared/validation"
|
||||
"github.com/gorilla/mux"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/sirupsen/logrus"
|
||||
|
||||
timing "github.com/mitchellh/go-server-timing"
|
||||
)
|
||||
|
||||
// Proxy is an HTTP server that proxies requests to a Client.
|
||||
type Proxy struct {
|
||||
client Client
|
||||
accessValidator *validation.Access
|
||||
logger *logrus.Logger
|
||||
}
|
||||
|
||||
// NewInsecureProxy creates a Proxy that talks to a Client at an origin.
|
||||
//
|
||||
// In insecure mode, the Proxy will allow all Command requests.
|
||||
func NewInsecureProxy(ctx context.Context, origin string) (*Proxy, error) {
|
||||
originURL, err := url.Parse(origin)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "must provide a valid database url")
|
||||
}
|
||||
|
||||
client, err := NewClient(ctx, originURL)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
err = client.Ping(ctx)
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not connect to the database")
|
||||
}
|
||||
|
||||
return &Proxy{client, nil, logrus.New()}, nil
|
||||
}
|
||||
|
||||
// NewSecureProxy creates a Proxy that talks to a Client at an origin.
|
||||
//
|
||||
// In secure mode, the Proxy will reject any Command requests that are
|
||||
// not authenticated by Cloudflare Access with a valid JWT.
|
||||
func NewSecureProxy(ctx context.Context, origin, authDomain, applicationAUD string) (*Proxy, error) {
|
||||
proxy, err := NewInsecureProxy(ctx, origin)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
validator, err := validation.NewAccessValidator(ctx, authDomain, authDomain, applicationAUD)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
proxy.accessValidator = validator
|
||||
return proxy, err
|
||||
}
|
||||
|
||||
// IsInsecure gets whether the Proxy will accept a Command from any source.
|
||||
func (proxy *Proxy) IsInsecure() bool {
|
||||
return proxy.accessValidator == nil
|
||||
}
|
||||
|
||||
// IsAllowed checks whether a http.Request is allowed to receive data.
|
||||
//
|
||||
// By default, requests must pass through Cloudflare Access for authentication.
|
||||
// If the proxy is explcitly set to insecure mode, all requests will be allowed.
|
||||
func (proxy *Proxy) IsAllowed(r *http.Request, verbose ...bool) bool {
|
||||
if proxy.IsInsecure() {
|
||||
return true
|
||||
}
|
||||
|
||||
// Access and Tunnel should prevent bad JWTs from even reaching the origin,
|
||||
// but validate tokens anyway as an abundance of caution.
|
||||
err := proxy.accessValidator.ValidateRequest(r.Context(), r)
|
||||
if err == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
// Warn administrators that invalid JWTs are being rejected. This is indicative
|
||||
// of either a misconfiguration of the CLI or a massive failure of upstream systems.
|
||||
if len(verbose) > 0 {
|
||||
proxy.httpLog(r, err).Error("Failed JWT authentication")
|
||||
}
|
||||
|
||||
return false
|
||||
}
|
||||
|
||||
// Start the Proxy at a given address and notify the listener channel when the server is online.
|
||||
func (proxy *Proxy) Start(ctx context.Context, addr string, listenerC chan<- net.Listener) error {
|
||||
// STOR-611: use a seperate listener and consider web socket support.
|
||||
httpListener, err := hello.CreateTLSListener(addr)
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "could not create listener at %s", addr)
|
||||
}
|
||||
|
||||
errC := make(chan error)
|
||||
defer close(errC)
|
||||
|
||||
// Starts the HTTP server and begins to serve requests.
|
||||
go func() {
|
||||
errC <- proxy.httpListen(ctx, httpListener)
|
||||
}()
|
||||
|
||||
// Continually ping the server until it comes online or 10 attempts fail.
|
||||
go func() {
|
||||
var err error
|
||||
for i := 0; i < 10; i++ {
|
||||
_, err = http.Get("http://" + httpListener.Addr().String())
|
||||
|
||||
// Once no error was detected, notify the listener channel and return.
|
||||
if err == nil {
|
||||
listenerC <- httpListener
|
||||
return
|
||||
}
|
||||
|
||||
// Backoff between requests to ping the server.
|
||||
<-time.After(1 * time.Second)
|
||||
}
|
||||
errC <- errors.Wrap(err, "took too long for the http server to start")
|
||||
}()
|
||||
|
||||
return <-errC
|
||||
}
|
||||
|
||||
// httpListen starts the httpServer and blocks until the context closes.
|
||||
func (proxy *Proxy) httpListen(ctx context.Context, listener net.Listener) error {
|
||||
httpServer := &http.Server{
|
||||
Addr: listener.Addr().String(),
|
||||
Handler: timing.Middleware(proxy.httpRouter(), nil),
|
||||
ReadTimeout: 10 * time.Second,
|
||||
WriteTimeout: 60 * time.Second,
|
||||
IdleTimeout: 60 * time.Second,
|
||||
}
|
||||
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
httpServer.Close()
|
||||
listener.Close()
|
||||
}()
|
||||
|
||||
return httpServer.Serve(listener)
|
||||
}
|
||||
|
||||
// httpRouter creates a mux.Router for the Proxy.
|
||||
func (proxy *Proxy) httpRouter() *mux.Router {
|
||||
router := mux.NewRouter()
|
||||
|
||||
router.HandleFunc("/ping", proxy.httpPing()).Methods("GET", "HEAD")
|
||||
router.HandleFunc("/submit", proxy.httpSubmit()).Methods("POST")
|
||||
|
||||
return router
|
||||
}
|
||||
|
||||
// httpPing tests the connection to the database.
|
||||
//
|
||||
// By default, this endpoint is unauthenticated to allow for health checks.
|
||||
// To enable authentication, Cloudflare Access must be enabled on this route.
|
||||
func (proxy *Proxy) httpPing() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
ctx := r.Context()
|
||||
metric := timing.FromContext(ctx).NewMetric("db").Start()
|
||||
err := proxy.client.Ping(ctx)
|
||||
metric.Stop()
|
||||
|
||||
if err == nil {
|
||||
proxy.httpRespond(w, r, http.StatusOK, "")
|
||||
} else {
|
||||
proxy.httpRespondErr(w, r, http.StatusInternalServerError, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// httpSubmit sends a command to the database and returns its response.
|
||||
//
|
||||
// By default, this endpoint will reject requests that do not pass through Cloudflare Access.
|
||||
// To disable authentication, the --insecure flag must be specified in the command line.
|
||||
func (proxy *Proxy) httpSubmit() http.HandlerFunc {
|
||||
return func(w http.ResponseWriter, r *http.Request) {
|
||||
if !proxy.IsAllowed(r, true) {
|
||||
proxy.httpRespondErr(w, r, http.StatusForbidden, fmt.Errorf(""))
|
||||
return
|
||||
}
|
||||
|
||||
var cmd Command
|
||||
err := json.NewDecoder(r.Body).Decode(&cmd)
|
||||
if err != nil {
|
||||
proxy.httpRespondErr(w, r, http.StatusBadRequest, err)
|
||||
return
|
||||
}
|
||||
|
||||
ctx := r.Context()
|
||||
metric := timing.FromContext(ctx).NewMetric("db").Start()
|
||||
data, err := proxy.client.Submit(ctx, &cmd)
|
||||
metric.Stop()
|
||||
|
||||
if err != nil {
|
||||
proxy.httpRespondErr(w, r, http.StatusUnprocessableEntity, err)
|
||||
return
|
||||
}
|
||||
|
||||
w.Header().Set("Content-type", "application/json")
|
||||
err = json.NewEncoder(w).Encode(data)
|
||||
if err != nil {
|
||||
proxy.httpRespondErr(w, r, http.StatusInternalServerError, err)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// httpRespond writes a status code and string response to the response writer.
|
||||
func (proxy *Proxy) httpRespond(w http.ResponseWriter, r *http.Request, status int, message string) {
|
||||
w.WriteHeader(status)
|
||||
|
||||
// Only expose the message detail of the reponse if the request is not HEAD
|
||||
// and the user is authenticated. For example, this prevents an unauthenticated
|
||||
// failed health check from accidentally leaking sensitive information about the Client.
|
||||
if r.Method != http.MethodHead && proxy.IsAllowed(r) {
|
||||
if message == "" {
|
||||
message = http.StatusText(status)
|
||||
}
|
||||
fmt.Fprint(w, message)
|
||||
}
|
||||
}
|
||||
|
||||
// httpRespondErr is similar to httpRespond, except it formats errors to be more friendly.
|
||||
func (proxy *Proxy) httpRespondErr(w http.ResponseWriter, r *http.Request, defaultStatus int, err error) {
|
||||
status, err := httpError(defaultStatus, err)
|
||||
|
||||
proxy.httpRespond(w, r, status, err.Error())
|
||||
proxy.httpLog(r, err).Warn("Database connect error")
|
||||
}
|
||||
|
||||
// httpLog returns a logrus.Entry that is formatted to output a request Cf-ray.
|
||||
func (proxy *Proxy) httpLog(r *http.Request, err error) *logrus.Entry {
|
||||
return proxy.logger.WithContext(r.Context()).WithField("CF-RAY", r.Header.Get("Cf-ray")).WithError(err)
|
||||
}
|
||||
|
||||
// httpError extracts common errors and returns an status code and friendly error.
|
||||
func httpError(defaultStatus int, err error) (int, error) {
|
||||
if err == nil {
|
||||
return http.StatusNotImplemented, fmt.Errorf("error expected but found none")
|
||||
}
|
||||
|
||||
if err == io.EOF {
|
||||
return http.StatusBadRequest, fmt.Errorf("request body cannot be empty")
|
||||
}
|
||||
|
||||
if err == context.DeadlineExceeded {
|
||||
return http.StatusRequestTimeout, err
|
||||
}
|
||||
|
||||
_, ok := err.(net.Error)
|
||||
if ok {
|
||||
return http.StatusRequestTimeout, err
|
||||
}
|
||||
|
||||
if err == context.Canceled {
|
||||
// Does not exist in Golang, but would be: http.StatusClientClosedWithoutResponse
|
||||
return 444, err
|
||||
}
|
||||
|
||||
return defaultStatus, err
|
||||
}
|
|
@ -1,238 +0,0 @@
|
|||
package dbconnect
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"io"
|
||||
"io/ioutil"
|
||||
"net"
|
||||
"net/http"
|
||||
"net/http/httptest"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/gorilla/mux"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewInsecureProxy(t *testing.T) {
|
||||
origins := []string{
|
||||
"",
|
||||
":/",
|
||||
"http://localhost",
|
||||
"tcp://localhost:9000?debug=true",
|
||||
"mongodb://127.0.0.1",
|
||||
}
|
||||
|
||||
for _, origin := range origins {
|
||||
proxy, err := NewInsecureProxy(context.Background(), origin)
|
||||
|
||||
assert.Error(t, err)
|
||||
assert.Empty(t, proxy)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProxyIsAllowed(t *testing.T) {
|
||||
proxy := helperNewProxy(t)
|
||||
req := httptest.NewRequest("GET", "https://1.1.1.1/ping", nil)
|
||||
assert.True(t, proxy.IsAllowed(req))
|
||||
|
||||
proxy = helperNewProxy(t, true)
|
||||
req.Header.Set("Cf-access-jwt-assertion", "xxx")
|
||||
assert.False(t, proxy.IsAllowed(req))
|
||||
}
|
||||
|
||||
func TestProxyStart(t *testing.T) {
|
||||
proxy := helperNewProxy(t)
|
||||
ctx := context.Background()
|
||||
listenerC := make(chan net.Listener)
|
||||
|
||||
err := proxy.Start(ctx, "1.1.1.1:", listenerC)
|
||||
assert.Error(t, err)
|
||||
|
||||
err = proxy.Start(ctx, "127.0.0.1:-1", listenerC)
|
||||
assert.Error(t, err)
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, 0)
|
||||
defer cancel()
|
||||
|
||||
err = proxy.Start(ctx, "127.0.0.1:", listenerC)
|
||||
assert.IsType(t, http.ErrServerClosed, err)
|
||||
}
|
||||
|
||||
func TestProxyHTTPRouter(t *testing.T) {
|
||||
proxy := helperNewProxy(t)
|
||||
router := proxy.httpRouter()
|
||||
|
||||
tests := []struct {
|
||||
path string
|
||||
method string
|
||||
valid bool
|
||||
}{
|
||||
{"", "GET", false},
|
||||
{"/", "GET", false},
|
||||
{"/ping", "GET", true},
|
||||
{"/ping", "HEAD", true},
|
||||
{"/ping", "POST", false},
|
||||
{"/submit", "POST", true},
|
||||
{"/submit", "GET", false},
|
||||
{"/submit/extra", "POST", false},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
match := &mux.RouteMatch{}
|
||||
ok := router.Match(httptest.NewRequest(test.method, "https://1.1.1.1"+test.path, nil), match)
|
||||
|
||||
assert.True(t, ok == test.valid, test.path)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProxyHTTPPing(t *testing.T) {
|
||||
proxy := helperNewProxy(t)
|
||||
|
||||
server := httptest.NewServer(proxy.httpPing())
|
||||
defer server.Close()
|
||||
client := server.Client()
|
||||
|
||||
res, err := client.Get(server.URL)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, http.StatusOK, res.StatusCode)
|
||||
assert.Equal(t, int64(2), res.ContentLength)
|
||||
|
||||
res, err = client.Head(server.URL)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, http.StatusOK, res.StatusCode)
|
||||
assert.Equal(t, int64(-1), res.ContentLength)
|
||||
}
|
||||
|
||||
func TestProxyHTTPSubmit(t *testing.T) {
|
||||
proxy := helperNewProxy(t)
|
||||
|
||||
server := httptest.NewServer(proxy.httpSubmit())
|
||||
defer server.Close()
|
||||
client := server.Client()
|
||||
|
||||
tests := []struct {
|
||||
input string
|
||||
status int
|
||||
output string
|
||||
}{
|
||||
{"", http.StatusBadRequest, "request body cannot be empty"},
|
||||
{"{}", http.StatusBadRequest, "cannot provide an empty statement"},
|
||||
{"{\"statement\":\"Ok\"}", http.StatusUnprocessableEntity, "cannot provide invalid sql mode: ''"},
|
||||
{"{\"statement\":\"Ok\",\"mode\":\"query\"}", http.StatusUnprocessableEntity, "near \"Ok\": syntax error"},
|
||||
{"{\"statement\":\"CREATE TABLE t (a INT);\",\"mode\":\"exec\"}", http.StatusOK, "{\"last_insert_id\":0,\"rows_affected\":0}\n"},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
res, err := client.Post(server.URL, "application/json", strings.NewReader(test.input))
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, test.status, res.StatusCode)
|
||||
if res.StatusCode > http.StatusOK {
|
||||
assert.Equal(t, "text/plain; charset=utf-8", res.Header.Get("Content-type"))
|
||||
} else {
|
||||
assert.Equal(t, "application/json", res.Header.Get("Content-type"))
|
||||
}
|
||||
|
||||
data, err := ioutil.ReadAll(res.Body)
|
||||
defer res.Body.Close()
|
||||
str := string(data)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, test.output, str)
|
||||
}
|
||||
}
|
||||
|
||||
func TestProxyHTTPSubmitForbidden(t *testing.T) {
|
||||
proxy := helperNewProxy(t, true)
|
||||
|
||||
server := httptest.NewServer(proxy.httpSubmit())
|
||||
defer server.Close()
|
||||
client := server.Client()
|
||||
|
||||
res, err := client.Get(server.URL)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, http.StatusForbidden, res.StatusCode)
|
||||
assert.Zero(t, res.ContentLength)
|
||||
}
|
||||
|
||||
func TestProxyHTTPRespond(t *testing.T) {
|
||||
proxy := helperNewProxy(t)
|
||||
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
proxy.httpRespond(w, r, http.StatusAccepted, "Hello")
|
||||
}))
|
||||
defer server.Close()
|
||||
client := server.Client()
|
||||
|
||||
res, err := client.Get(server.URL)
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, http.StatusAccepted, res.StatusCode)
|
||||
assert.Equal(t, int64(5), res.ContentLength)
|
||||
|
||||
data, err := ioutil.ReadAll(res.Body)
|
||||
defer res.Body.Close()
|
||||
assert.Equal(t, []byte("Hello"), data)
|
||||
}
|
||||
|
||||
func TestProxyHTTPRespondForbidden(t *testing.T) {
|
||||
proxy := helperNewProxy(t, true)
|
||||
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
|
||||
proxy.httpRespond(w, r, http.StatusAccepted, "Hello")
|
||||
}))
|
||||
defer server.Close()
|
||||
client := server.Client()
|
||||
|
||||
res, err := client.Get(server.URL)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, http.StatusAccepted, res.StatusCode)
|
||||
assert.Equal(t, int64(0), res.ContentLength)
|
||||
}
|
||||
|
||||
func TestHTTPError(t *testing.T) {
|
||||
_, errTimeout := net.DialTimeout("tcp", "127.0.0.1", 0)
|
||||
assert.Error(t, errTimeout)
|
||||
|
||||
tests := []struct {
|
||||
input error
|
||||
status int
|
||||
output error
|
||||
}{
|
||||
{nil, http.StatusNotImplemented, fmt.Errorf("error expected but found none")},
|
||||
{io.EOF, http.StatusBadRequest, fmt.Errorf("request body cannot be empty")},
|
||||
{context.DeadlineExceeded, http.StatusRequestTimeout, nil},
|
||||
{context.Canceled, 444, nil},
|
||||
{errTimeout, http.StatusRequestTimeout, nil},
|
||||
{fmt.Errorf(""), http.StatusInternalServerError, nil},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
status, err := httpError(http.StatusInternalServerError, test.input)
|
||||
|
||||
assert.Error(t, err)
|
||||
assert.Equal(t, test.status, status)
|
||||
if test.output == nil {
|
||||
test.output = test.input
|
||||
}
|
||||
assert.Equal(t, test.output, err)
|
||||
}
|
||||
}
|
||||
|
||||
func helperNewProxy(t *testing.T, secure ...bool) *Proxy {
|
||||
t.Helper()
|
||||
|
||||
proxy, err := NewSecureProxy(context.Background(), "file::memory:?cache=shared", "test.cloudflareaccess.com", "")
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, proxy)
|
||||
|
||||
if len(secure) == 0 {
|
||||
proxy.accessValidator = nil // Mark as insecure
|
||||
}
|
||||
|
||||
return proxy
|
||||
}
|
318
dbconnect/sql.go
318
dbconnect/sql.go
|
@ -1,318 +0,0 @@
|
|||
package dbconnect
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"reflect"
|
||||
"strings"
|
||||
|
||||
"github.com/jmoiron/sqlx"
|
||||
"github.com/pkg/errors"
|
||||
"github.com/xo/dburl"
|
||||
|
||||
// SQL drivers self-register with the database/sql package.
|
||||
// https://github.com/golang/go/wiki/SQLDrivers
|
||||
_ "github.com/denisenkom/go-mssqldb"
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
_ "github.com/mattn/go-sqlite3"
|
||||
|
||||
"github.com/kshvakov/clickhouse"
|
||||
"github.com/lib/pq"
|
||||
)
|
||||
|
||||
// SQLClient is a Client that talks to a SQL database.
|
||||
type SQLClient struct {
|
||||
Dialect string
|
||||
driver *sqlx.DB
|
||||
}
|
||||
|
||||
// NewSQLClient creates a SQL client based on its URL scheme.
|
||||
func NewSQLClient(ctx context.Context, originURL *url.URL) (Client, error) {
|
||||
res, err := dburl.Parse(originURL.String())
|
||||
if err != nil {
|
||||
helpText := fmt.Sprintf("supported drivers: %+q, see documentation for more details: %s", sql.Drivers(), "https://godoc.org/github.com/xo/dburl")
|
||||
return nil, fmt.Errorf("could not parse sql database url '%s': %s\n%s", originURL, err.Error(), helpText)
|
||||
}
|
||||
|
||||
// Establishes the driver, but does not test the connection.
|
||||
driver, err := sqlx.Open(res.Driver, res.DSN)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("could not open sql driver %s: %s\n%s", res.Driver, err.Error(), res.DSN)
|
||||
}
|
||||
|
||||
// Closes the driver, will occur when the context finishes.
|
||||
go func() {
|
||||
<-ctx.Done()
|
||||
driver.Close()
|
||||
}()
|
||||
|
||||
return &SQLClient{driver.DriverName(), driver}, nil
|
||||
}
|
||||
|
||||
// Ping verifies a connection to the database is still alive.
|
||||
func (client *SQLClient) Ping(ctx context.Context) error {
|
||||
return client.driver.PingContext(ctx)
|
||||
}
|
||||
|
||||
// Submit queries or executes a command to the SQL database.
|
||||
func (client *SQLClient) Submit(ctx context.Context, cmd *Command) (interface{}, error) {
|
||||
txx, err := cmd.ValidateSQL(client.Dialect)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
ctx, cancel := context.WithTimeout(ctx, cmd.Timeout)
|
||||
defer cancel()
|
||||
|
||||
var res interface{}
|
||||
|
||||
// Get the next available sql.Conn and submit the Command.
|
||||
err = sqlConn(ctx, client.driver, txx, func(conn *sql.Conn) error {
|
||||
stmt := cmd.Statement
|
||||
args := cmd.Arguments.Positional
|
||||
|
||||
if cmd.Mode == "query" {
|
||||
res, err = sqlQuery(ctx, conn, stmt, args)
|
||||
} else {
|
||||
res, err = sqlExec(ctx, conn, stmt, args)
|
||||
}
|
||||
|
||||
return err
|
||||
})
|
||||
|
||||
return res, err
|
||||
}
|
||||
|
||||
// ValidateSQL extends the contract of Command for SQL dialects:
|
||||
// mode is conformed, arguments are []sql.NamedArg, and isolation is a sql.IsolationLevel.
|
||||
//
|
||||
// When the command should not be wrapped in a transaction, *sql.TxOptions and error will both be nil.
|
||||
func (cmd *Command) ValidateSQL(dialect string) (*sql.TxOptions, error) {
|
||||
err := cmd.Validate()
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
mode, err := sqlMode(cmd.Mode)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Mutates Arguments to only use positional arguments with the type sql.NamedArg.
|
||||
// This is a required by the sql.Driver before submitting arguments.
|
||||
cmd.Arguments.sql(dialect)
|
||||
|
||||
iso, err := sqlIsolation(cmd.Isolation)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// When isolation is out-of-range, this is indicative that no
|
||||
// transaction should be executed and sql.TxOptions should be nil.
|
||||
if iso < sql.LevelDefault {
|
||||
return nil, nil
|
||||
}
|
||||
|
||||
// In query mode, execute the transaction in read-only, unless it's Microsoft SQL
|
||||
// which does not support that type of transaction.
|
||||
readOnly := mode == "query" && dialect != "mssql"
|
||||
|
||||
return &sql.TxOptions{Isolation: iso, ReadOnly: readOnly}, nil
|
||||
}
|
||||
|
||||
// sqlConn gets the next available sql.Conn in the connection pool and runs a function to use it.
|
||||
//
|
||||
// If the transaction options are nil, run the useIt function outside a transaction.
|
||||
// This is potentially an unsafe operation if the command does not clean up its state.
|
||||
func sqlConn(ctx context.Context, driver *sqlx.DB, txx *sql.TxOptions, useIt func(*sql.Conn) error) error {
|
||||
conn, err := driver.Conn(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer conn.Close()
|
||||
|
||||
// If transaction options are specified, begin and defer a rollback to catch errors.
|
||||
var tx *sql.Tx
|
||||
if txx != nil {
|
||||
tx, err = conn.BeginTx(ctx, txx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
defer tx.Rollback()
|
||||
}
|
||||
|
||||
err = useIt(conn)
|
||||
|
||||
// Check if useIt was successful and a transaction exists before committing.
|
||||
if err == nil && tx != nil {
|
||||
err = tx.Commit()
|
||||
}
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
// sqlQuery queries rows on a sql.Conn and returns an array of result objects.
|
||||
func sqlQuery(ctx context.Context, conn *sql.Conn, stmt string, args []interface{}) ([]map[string]interface{}, error) {
|
||||
rows, err := conn.QueryContext(ctx, stmt, args...)
|
||||
if err == nil {
|
||||
return sqlRows(rows)
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// sqlExec executes a command on a sql.Conn and returns the result of the operation.
|
||||
func sqlExec(ctx context.Context, conn *sql.Conn, stmt string, args []interface{}) (sqlResult, error) {
|
||||
exec, err := conn.ExecContext(ctx, stmt, args...)
|
||||
if err == nil {
|
||||
return sqlResultFrom(exec), nil
|
||||
}
|
||||
return sqlResult{}, err
|
||||
}
|
||||
|
||||
// sql mutates Arguments to contain a positional []sql.NamedArg.
|
||||
//
|
||||
// The actual return type is []interface{} due to the native Golang
|
||||
// function signatures for sql.Exec and sql.Query being generic.
|
||||
func (args *Arguments) sql(dialect string) {
|
||||
result := args.Positional
|
||||
|
||||
for i, val := range result {
|
||||
result[i] = sqlArg("", val, dialect)
|
||||
}
|
||||
|
||||
for key, val := range args.Named {
|
||||
result = append(result, sqlArg(key, val, dialect))
|
||||
}
|
||||
|
||||
args.Positional = result
|
||||
args.Named = map[string]interface{}{}
|
||||
}
|
||||
|
||||
// sqlArg creates a sql.NamedArg from a key-value pair and an optional dialect.
|
||||
//
|
||||
// Certain dialects will need to wrap objects, such as arrays, to conform its driver requirements.
|
||||
func sqlArg(key, val interface{}, dialect string) sql.NamedArg {
|
||||
switch reflect.ValueOf(val).Kind() {
|
||||
|
||||
// PostgreSQL and Clickhouse require arrays to be wrapped before
|
||||
// being inserted into the driver interface.
|
||||
case reflect.Slice, reflect.Array:
|
||||
switch dialect {
|
||||
case "postgres":
|
||||
val = pq.Array(val)
|
||||
case "clickhouse":
|
||||
val = clickhouse.Array(val)
|
||||
}
|
||||
}
|
||||
|
||||
return sql.Named(fmt.Sprint(key), val)
|
||||
}
|
||||
|
||||
// sqlIsolation tries to match a string to a sql.IsolationLevel.
|
||||
func sqlIsolation(str string) (sql.IsolationLevel, error) {
|
||||
if str == "none" {
|
||||
return sql.IsolationLevel(-1), nil
|
||||
}
|
||||
|
||||
for iso := sql.LevelDefault; ; iso++ {
|
||||
if iso > sql.LevelLinearizable {
|
||||
return -1, fmt.Errorf("cannot provide an invalid sql isolation level: '%s'", str)
|
||||
}
|
||||
|
||||
if str == "" || strings.EqualFold(iso.String(), strings.ReplaceAll(str, "_", " ")) {
|
||||
return iso, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// sqlMode tries to match a string to a command mode: 'query' or 'exec' for now.
|
||||
func sqlMode(str string) (string, error) {
|
||||
switch str {
|
||||
case "query", "exec":
|
||||
return str, nil
|
||||
default:
|
||||
return "", fmt.Errorf("cannot provide invalid sql mode: '%s'", str)
|
||||
}
|
||||
}
|
||||
|
||||
// sqlRows scans through a SQL result set and returns an array of objects.
|
||||
func sqlRows(rows *sql.Rows) ([]map[string]interface{}, error) {
|
||||
columns, err := rows.Columns()
|
||||
if err != nil {
|
||||
return nil, errors.Wrap(err, "could not extract columns from result")
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
types, err := rows.ColumnTypes()
|
||||
if err != nil {
|
||||
// Some drivers do not support type extraction, so fail silently and continue.
|
||||
types = make([]*sql.ColumnType, len(columns))
|
||||
}
|
||||
|
||||
values := make([]interface{}, len(columns))
|
||||
pointers := make([]interface{}, len(columns))
|
||||
|
||||
var results []map[string]interface{}
|
||||
for rows.Next() {
|
||||
for i := range columns {
|
||||
pointers[i] = &values[i]
|
||||
}
|
||||
rows.Scan(pointers...)
|
||||
|
||||
// Convert a row, an array of values, into an object where
|
||||
// each key is the name of its respective column.
|
||||
entry := make(map[string]interface{})
|
||||
for i, col := range columns {
|
||||
entry[col] = sqlValue(values[i], types[i])
|
||||
}
|
||||
results = append(results, entry)
|
||||
}
|
||||
|
||||
return results, nil
|
||||
}
|
||||
|
||||
// sqlValue handles special cases where sql.Rows does not return a "human-readable" object.
|
||||
func sqlValue(val interface{}, col *sql.ColumnType) interface{} {
|
||||
bytes, ok := val.([]byte)
|
||||
if ok {
|
||||
// Opportunistically check for embeded JSON and convert it to a first-class object.
|
||||
var embeded interface{}
|
||||
if json.Unmarshal(bytes, &embeded) == nil {
|
||||
return embeded
|
||||
}
|
||||
|
||||
// STOR-604: investigate a way to coerce PostgreSQL arrays '{a, b, ...}' into JSON.
|
||||
// Although easy with strings, it becomes more difficult with special types like INET[].
|
||||
|
||||
return string(bytes)
|
||||
}
|
||||
|
||||
return val
|
||||
}
|
||||
|
||||
// sqlResult is a thin wrapper around sql.Result.
|
||||
type sqlResult struct {
|
||||
LastInsertId int64 `json:"last_insert_id"`
|
||||
RowsAffected int64 `json:"rows_affected"`
|
||||
}
|
||||
|
||||
// sqlResultFrom converts sql.Result into a JSON-marshable sqlResult.
|
||||
func sqlResultFrom(res sql.Result) sqlResult {
|
||||
insertID, errID := res.LastInsertId()
|
||||
rowsAffected, errRows := res.RowsAffected()
|
||||
|
||||
// If an error occurs when extracting the result, it is because the
|
||||
// driver does not support that specific field. Instead of passing this
|
||||
// to the user, omit the field in the response.
|
||||
if errID != nil {
|
||||
insertID = -1
|
||||
}
|
||||
if errRows != nil {
|
||||
rowsAffected = -1
|
||||
}
|
||||
|
||||
return sqlResult{insertID, rowsAffected}
|
||||
}
|
|
@ -1,336 +0,0 @@
|
|||
package dbconnect
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql"
|
||||
"fmt"
|
||||
"net/url"
|
||||
"strings"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/kshvakov/clickhouse"
|
||||
"github.com/lib/pq"
|
||||
|
||||
"github.com/DATA-DOG/go-sqlmock"
|
||||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
func TestNewSQLClient(t *testing.T) {
|
||||
originURLs := []string{
|
||||
"postgres://localhost",
|
||||
"cockroachdb://localhost:1337",
|
||||
"postgresql://user:pass@127.0.0.1",
|
||||
"mysql://localhost",
|
||||
"clickhouse://127.0.0.1:9000/?debug",
|
||||
"sqlite3::memory:",
|
||||
"file:test.db?cache=shared",
|
||||
}
|
||||
|
||||
for _, originURL := range originURLs {
|
||||
origin, _ := url.Parse(originURL)
|
||||
_, err := NewSQLClient(context.Background(), origin)
|
||||
|
||||
assert.NoError(t, err, originURL)
|
||||
}
|
||||
|
||||
originURLs = []string{
|
||||
"",
|
||||
"/",
|
||||
"http://localhost",
|
||||
"coolthing://user:pass@127.0.0.1",
|
||||
}
|
||||
|
||||
for _, originURL := range originURLs {
|
||||
origin, _ := url.Parse(originURL)
|
||||
_, err := NewSQLClient(context.Background(), origin)
|
||||
|
||||
assert.Error(t, err, originURL)
|
||||
}
|
||||
}
|
||||
|
||||
func TestArgumentsSQL(t *testing.T) {
|
||||
args := []Arguments{
|
||||
Arguments{
|
||||
Positional: []interface{}{
|
||||
"val", 10, 3.14,
|
||||
},
|
||||
},
|
||||
Arguments{
|
||||
Named: map[string]interface{}{
|
||||
"key": time.Unix(0, 0),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
var nameType sql.NamedArg
|
||||
for _, arg := range args {
|
||||
arg.sql("")
|
||||
for _, named := range arg.Positional {
|
||||
assert.IsType(t, nameType, named)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSQLArg(t *testing.T) {
|
||||
tests := []struct {
|
||||
key interface{}
|
||||
val interface{}
|
||||
dialect string
|
||||
arg sql.NamedArg
|
||||
}{
|
||||
{"key", "val", "mssql", sql.Named("key", "val")},
|
||||
{0, 1, "sqlite3", sql.Named("0", 1)},
|
||||
{1, []string{"a", "b", "c"}, "postgres", sql.Named("1", pq.Array([]string{"a", "b", "c"}))},
|
||||
{"in", []uint{0, 1}, "clickhouse", sql.Named("in", clickhouse.Array([]uint{0, 1}))},
|
||||
{"", time.Unix(0, 0), "", sql.Named("", time.Unix(0, 0))},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
arg := sqlArg(test.key, test.val, test.dialect)
|
||||
assert.Equal(t, test.arg, arg, test.key)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSQLIsolation(t *testing.T) {
|
||||
tests := []struct {
|
||||
str string
|
||||
iso sql.IsolationLevel
|
||||
}{
|
||||
{"", sql.LevelDefault},
|
||||
{"DEFAULT", sql.LevelDefault},
|
||||
{"read_UNcommitted", sql.LevelReadUncommitted},
|
||||
{"serializable", sql.LevelSerializable},
|
||||
{"none", sql.IsolationLevel(-1)},
|
||||
{"SNAP shot", -2},
|
||||
{"blah", -2},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
iso, err := sqlIsolation(test.str)
|
||||
|
||||
if test.iso < -1 {
|
||||
assert.Error(t, err, test.str)
|
||||
} else {
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, test.iso, iso, test.str)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func TestSQLMode(t *testing.T) {
|
||||
modes := []string{
|
||||
"query",
|
||||
"exec",
|
||||
}
|
||||
|
||||
for _, mode := range modes {
|
||||
actual, err := sqlMode(mode)
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, strings.ToLower(mode), actual, mode)
|
||||
}
|
||||
|
||||
modes = []string{
|
||||
"",
|
||||
"blah",
|
||||
}
|
||||
|
||||
for _, mode := range modes {
|
||||
_, err := sqlMode(mode)
|
||||
|
||||
assert.Error(t, err)
|
||||
}
|
||||
}
|
||||
|
||||
func helperRows(mockRows *sqlmock.Rows) *sql.Rows {
|
||||
db, mock, _ := sqlmock.New()
|
||||
mock.ExpectQuery("SELECT").WillReturnRows(mockRows)
|
||||
rows, _ := db.Query("SELECT")
|
||||
return rows
|
||||
}
|
||||
|
||||
func TestSQLRows(t *testing.T) {
|
||||
actual, err := sqlRows(helperRows(sqlmock.NewRows(
|
||||
[]string{"name", "age", "dept"}).
|
||||
AddRow("alice", 19, "prod")))
|
||||
expected := []map[string]interface{}{map[string]interface{}{
|
||||
"name": "alice",
|
||||
"age": int64(19),
|
||||
"dept": "prod"}}
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.ElementsMatch(t, expected, actual)
|
||||
}
|
||||
|
||||
func TestSQLValue(t *testing.T) {
|
||||
tests := []struct {
|
||||
input interface{}
|
||||
output interface{}
|
||||
}{
|
||||
{"hello", "hello"},
|
||||
{1, 1},
|
||||
{false, false},
|
||||
{[]byte("random"), "random"},
|
||||
{[]byte("{\"json\":true}"), map[string]interface{}{"json": true}},
|
||||
{[]byte("[]"), []interface{}{}},
|
||||
}
|
||||
|
||||
for _, test := range tests {
|
||||
assert.Equal(t, test.output, sqlValue(test.input, nil), test.input)
|
||||
}
|
||||
}
|
||||
|
||||
func TestSQLResultFrom(t *testing.T) {
|
||||
res := sqlResultFrom(sqlmock.NewResult(1, 2))
|
||||
assert.Equal(t, sqlResult{1, 2}, res)
|
||||
|
||||
res = sqlResultFrom(sqlmock.NewErrorResult(fmt.Errorf("")))
|
||||
assert.Equal(t, sqlResult{-1, -1}, res)
|
||||
}
|
||||
|
||||
func helperSQLite3(t *testing.T) (context.Context, Client) {
|
||||
t.Helper()
|
||||
|
||||
ctx := context.Background()
|
||||
url, _ := url.Parse("file::memory:?cache=shared")
|
||||
|
||||
sqlite3, err := NewSQLClient(ctx, url)
|
||||
assert.NoError(t, err)
|
||||
|
||||
return ctx, sqlite3
|
||||
}
|
||||
|
||||
func TestPing(t *testing.T) {
|
||||
ctx, sqlite3 := helperSQLite3(t)
|
||||
err := sqlite3.Ping(ctx)
|
||||
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
|
||||
func TestSubmit(t *testing.T) {
|
||||
ctx, sqlite3 := helperSQLite3(t)
|
||||
|
||||
res, err := sqlite3.Submit(ctx, &Command{
|
||||
Statement: "CREATE TABLE t (a INTEGER, b FLOAT, c TEXT, d BLOB);",
|
||||
Mode: "exec",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, sqlResult{0, 0}, res)
|
||||
|
||||
res, err = sqlite3.Submit(ctx, &Command{
|
||||
Statement: "SELECT * FROM t;",
|
||||
Mode: "query",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.Empty(t, res)
|
||||
|
||||
res, err = sqlite3.Submit(ctx, &Command{
|
||||
Statement: "INSERT INTO t VALUES (?, ?, ?, ?);",
|
||||
Mode: "exec",
|
||||
Arguments: Arguments{
|
||||
Positional: []interface{}{
|
||||
1,
|
||||
3.14,
|
||||
"text",
|
||||
"blob",
|
||||
},
|
||||
},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, sqlResult{1, 1}, res)
|
||||
|
||||
res, err = sqlite3.Submit(ctx, &Command{
|
||||
Statement: "UPDATE t SET c = NULL;",
|
||||
Mode: "exec",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, sqlResult{1, 1}, res)
|
||||
|
||||
res, err = sqlite3.Submit(ctx, &Command{
|
||||
Statement: "SELECT * FROM t WHERE a = ?;",
|
||||
Mode: "query",
|
||||
Arguments: Arguments{
|
||||
Positional: []interface{}{1},
|
||||
},
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.Len(t, res, 1)
|
||||
|
||||
resf, ok := res.([]map[string]interface{})
|
||||
assert.True(t, ok)
|
||||
assert.EqualValues(t, map[string]interface{}{
|
||||
"a": int64(1),
|
||||
"b": 3.14,
|
||||
"c": nil,
|
||||
"d": "blob",
|
||||
}, resf[0])
|
||||
|
||||
res, err = sqlite3.Submit(ctx, &Command{
|
||||
Statement: "DROP TABLE t;",
|
||||
Mode: "exec",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, sqlResult{1, 1}, res)
|
||||
}
|
||||
|
||||
func TestSubmitTransaction(t *testing.T) {
|
||||
ctx, sqlite3 := helperSQLite3(t)
|
||||
|
||||
res, err := sqlite3.Submit(ctx, &Command{
|
||||
Statement: "BEGIN;",
|
||||
Mode: "exec",
|
||||
})
|
||||
assert.Error(t, err)
|
||||
assert.Empty(t, res)
|
||||
|
||||
res, err = sqlite3.Submit(ctx, &Command{
|
||||
Statement: "BEGIN; CREATE TABLE tt (a INT); COMMIT;",
|
||||
Mode: "exec",
|
||||
Isolation: "none",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.Equal(t, sqlResult{0, 0}, res)
|
||||
|
||||
rows, err := sqlite3.Submit(ctx, &Command{
|
||||
Statement: "SELECT * FROM tt;",
|
||||
Mode: "query",
|
||||
Isolation: "repeatable_read",
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
assert.Empty(t, rows)
|
||||
}
|
||||
|
||||
func TestSubmitTimeout(t *testing.T) {
|
||||
ctx, sqlite3 := helperSQLite3(t)
|
||||
|
||||
res, err := sqlite3.Submit(ctx, &Command{
|
||||
Statement: "SELECT * FROM t;",
|
||||
Mode: "query",
|
||||
Timeout: 1 * time.Nanosecond,
|
||||
})
|
||||
assert.Error(t, err)
|
||||
assert.Empty(t, res)
|
||||
}
|
||||
|
||||
func TestSubmitMode(t *testing.T) {
|
||||
ctx, sqlite3 := helperSQLite3(t)
|
||||
|
||||
res, err := sqlite3.Submit(ctx, &Command{
|
||||
Statement: "SELECT * FROM t;",
|
||||
Mode: "notanoption",
|
||||
})
|
||||
assert.Error(t, err)
|
||||
assert.Empty(t, res)
|
||||
}
|
||||
|
||||
func TestSubmitEmpty(t *testing.T) {
|
||||
ctx, sqlite3 := helperSQLite3(t)
|
||||
|
||||
res, err := sqlite3.Submit(ctx, &Command{
|
||||
Statement: "; ; ; ;",
|
||||
Mode: "query",
|
||||
})
|
||||
assert.Error(t, err)
|
||||
assert.Empty(t, res)
|
||||
}
|
|
@ -1,4 +0,0 @@
|
|||
FROM golang:1.12 as builder
|
||||
WORKDIR /go/src/github.com/cloudflare/cloudflared/
|
||||
RUN apt-get update
|
||||
COPY . .
|
|
@ -18,9 +18,9 @@ import (
|
|||
|
||||
"github.com/cloudflare/cloudflared/cmd/cloudflared/config"
|
||||
cfpath "github.com/cloudflare/cloudflared/cmd/cloudflared/path"
|
||||
"github.com/coreos/go-oidc/jose"
|
||||
homedir "github.com/mitchellh/go-homedir"
|
||||
gossh "golang.org/x/crypto/ssh"
|
||||
"gopkg.in/coreos/go-oidc.v1/jose"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
@ -16,8 +16,8 @@ import (
|
|||
|
||||
"github.com/cloudflare/cloudflared/cmd/cloudflared/config"
|
||||
cfpath "github.com/cloudflare/cloudflared/cmd/cloudflared/path"
|
||||
"github.com/coreos/go-oidc/jose"
|
||||
"github.com/stretchr/testify/assert"
|
||||
"gopkg.in/coreos/go-oidc.v1/jose"
|
||||
)
|
||||
|
||||
const (
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package validation
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"net/url"
|
||||
|
@ -10,21 +9,15 @@ import (
|
|||
|
||||
"net/http"
|
||||
|
||||
"github.com/coreos/go-oidc"
|
||||
"github.com/pkg/errors"
|
||||
"golang.org/x/net/idna"
|
||||
)
|
||||
|
||||
const (
|
||||
defaultScheme = "http"
|
||||
accessDomain = "cloudflareaccess.com"
|
||||
accessCertPath = "/cdn-cgi/access/certs"
|
||||
accessJwtHeader = "Cf-access-jwt-assertion"
|
||||
)
|
||||
const defaultScheme = "http"
|
||||
|
||||
var (
|
||||
supportedProtocols = []string{"http", "https", "rdp"}
|
||||
validationTimeout = time.Duration(30 * time.Second)
|
||||
validationTimeout = time.Duration(30 * time.Second)
|
||||
)
|
||||
|
||||
func ValidateHostname(hostname string) (string, error) {
|
||||
|
@ -204,50 +197,3 @@ func toggleProtocol(httpProtocol string) string {
|
|||
return httpProtocol
|
||||
}
|
||||
}
|
||||
|
||||
// Access checks if a JWT from Cloudflare Access is valid.
|
||||
type Access struct {
|
||||
verifier *oidc.IDTokenVerifier
|
||||
}
|
||||
|
||||
func NewAccessValidator(ctx context.Context, domain, issuer, applicationAUD string) (*Access, error) {
|
||||
domainURL, err := ValidateUrl(domain)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
issuerURL, err := ValidateUrl(issuer)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// An issuerURL from Cloudflare Access will always use HTTPS.
|
||||
issuerURL = strings.Replace(issuerURL, "http:", "https:", 1)
|
||||
|
||||
keySet := oidc.NewRemoteKeySet(ctx, domainURL+accessCertPath)
|
||||
return &Access{oidc.NewVerifier(issuerURL, keySet, &oidc.Config{ClientID: applicationAUD})}, nil
|
||||
}
|
||||
|
||||
func (a *Access) Validate(ctx context.Context, jwt string) error {
|
||||
token, err := a.verifier.Verify(ctx, jwt)
|
||||
|
||||
if err != nil {
|
||||
return errors.Wrapf(err, "token is invalid: %s", jwt)
|
||||
}
|
||||
|
||||
// Perform extra sanity checks, just to be safe.
|
||||
|
||||
if token == nil {
|
||||
return fmt.Errorf("token is nil: %s", jwt)
|
||||
}
|
||||
|
||||
if !strings.HasSuffix(token.Issuer, accessDomain) {
|
||||
return fmt.Errorf("token has non-cloudflare issuer of %s: %s", token.Issuer, jwt)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (a *Access) ValidateRequest(ctx context.Context, r *http.Request) error {
|
||||
return a.Validate(ctx, r.Header.Get(accessJwtHeader))
|
||||
}
|
||||
|
|
|
@ -320,39 +320,6 @@ func TestValidateHTTPService_NonResponsiveOrigin(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestNewAccessValidatorOk(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
url := "test.cloudflareaccess.com"
|
||||
access, err := NewAccessValidator(ctx, url, url, "")
|
||||
|
||||
assert.NoError(t, err)
|
||||
assert.NotNil(t, access)
|
||||
|
||||
assert.Error(t, access.Validate(ctx, ""))
|
||||
assert.Error(t, access.Validate(ctx, "invalid"))
|
||||
|
||||
req := httptest.NewRequest("GET", "https://test.cloudflareaccess.com", nil)
|
||||
req.Header.Set(accessJwtHeader, "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c")
|
||||
assert.Error(t, access.ValidateRequest(ctx, req))
|
||||
}
|
||||
|
||||
func TestNewAccessValidatorErr(t *testing.T) {
|
||||
ctx := context.Background()
|
||||
|
||||
urls := []string{
|
||||
"",
|
||||
"tcp://test.cloudflareaccess.com",
|
||||
"wss://cloudflarenone.com",
|
||||
}
|
||||
|
||||
for _, url := range urls {
|
||||
access, err := NewAccessValidator(ctx, url, url, "")
|
||||
|
||||
assert.Error(t, err, url)
|
||||
assert.Nil(t, access)
|
||||
}
|
||||
}
|
||||
|
||||
type testRoundTripper func(req *http.Request) (*http.Response, error)
|
||||
|
||||
func (f testRoundTripper) RoundTrip(req *http.Request) (*http.Response, error) {
|
||||
|
|
|
@ -1,202 +0,0 @@
|
|||
|
||||
Apache License
|
||||
Version 2.0, January 2004
|
||||
http://www.apache.org/licenses/
|
||||
|
||||
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
||||
|
||||
1. Definitions.
|
||||
|
||||
"License" shall mean the terms and conditions for use, reproduction,
|
||||
and distribution as defined by Sections 1 through 9 of this document.
|
||||
|
||||
"Licensor" shall mean the copyright owner or entity authorized by
|
||||
the copyright owner that is granting the License.
|
||||
|
||||
"Legal Entity" shall mean the union of the acting entity and all
|
||||
other entities that control, are controlled by, or are under common
|
||||
control with that entity. For the purposes of this definition,
|
||||
"control" means (i) the power, direct or indirect, to cause the
|
||||
direction or management of such entity, whether by contract or
|
||||
otherwise, or (ii) ownership of fifty percent (50%) or more of the
|
||||
outstanding shares, or (iii) beneficial ownership of such entity.
|
||||
|
||||
"You" (or "Your") shall mean an individual or Legal Entity
|
||||
exercising permissions granted by this License.
|
||||
|
||||
"Source" form shall mean the preferred form for making modifications,
|
||||
including but not limited to software source code, documentation
|
||||
source, and configuration files.
|
||||
|
||||
"Object" form shall mean any form resulting from mechanical
|
||||
transformation or translation of a Source form, including but
|
||||
not limited to compiled object code, generated documentation,
|
||||
and conversions to other media types.
|
||||
|
||||
"Work" shall mean the work of authorship, whether in Source or
|
||||
Object form, made available under the License, as indicated by a
|
||||
copyright notice that is included in or attached to the work
|
||||
(an example is provided in the Appendix below).
|
||||
|
||||
"Derivative Works" shall mean any work, whether in Source or Object
|
||||
form, that is based on (or derived from) the Work and for which the
|
||||
editorial revisions, annotations, elaborations, or other modifications
|
||||
represent, as a whole, an original work of authorship. For the purposes
|
||||
of this License, Derivative Works shall not include works that remain
|
||||
separable from, or merely link (or bind by name) to the interfaces of,
|
||||
the Work and Derivative Works thereof.
|
||||
|
||||
"Contribution" shall mean any work of authorship, including
|
||||
the original version of the Work and any modifications or additions
|
||||
to that Work or Derivative Works thereof, that is intentionally
|
||||
submitted to Licensor for inclusion in the Work by the copyright owner
|
||||
or by an individual or Legal Entity authorized to submit on behalf of
|
||||
the copyright owner. For the purposes of this definition, "submitted"
|
||||
means any form of electronic, verbal, or written communication sent
|
||||
to the Licensor or its representatives, including but not limited to
|
||||
communication on electronic mailing lists, source code control systems,
|
||||
and issue tracking systems that are managed by, or on behalf of, the
|
||||
Licensor for the purpose of discussing and improving the Work, but
|
||||
excluding communication that is conspicuously marked or otherwise
|
||||
designated in writing by the copyright owner as "Not a Contribution."
|
||||
|
||||
"Contributor" shall mean Licensor and any individual or Legal Entity
|
||||
on behalf of whom a Contribution has been received by Licensor and
|
||||
subsequently incorporated within the Work.
|
||||
|
||||
2. Grant of Copyright License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
copyright license to reproduce, prepare Derivative Works of,
|
||||
publicly display, publicly perform, sublicense, and distribute the
|
||||
Work and such Derivative Works in Source or Object form.
|
||||
|
||||
3. Grant of Patent License. Subject to the terms and conditions of
|
||||
this License, each Contributor hereby grants to You a perpetual,
|
||||
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
|
||||
(except as stated in this section) patent license to make, have made,
|
||||
use, offer to sell, sell, import, and otherwise transfer the Work,
|
||||
where such license applies only to those patent claims licensable
|
||||
by such Contributor that are necessarily infringed by their
|
||||
Contribution(s) alone or by combination of their Contribution(s)
|
||||
with the Work to which such Contribution(s) was submitted. If You
|
||||
institute patent litigation against any entity (including a
|
||||
cross-claim or counterclaim in a lawsuit) alleging that the Work
|
||||
or a Contribution incorporated within the Work constitutes direct
|
||||
or contributory patent infringement, then any patent licenses
|
||||
granted to You under this License for that Work shall terminate
|
||||
as of the date such litigation is filed.
|
||||
|
||||
4. Redistribution. You may reproduce and distribute copies of the
|
||||
Work or Derivative Works thereof in any medium, with or without
|
||||
modifications, and in Source or Object form, provided that You
|
||||
meet the following conditions:
|
||||
|
||||
(a) You must give any other recipients of the Work or
|
||||
Derivative Works a copy of this License; and
|
||||
|
||||
(b) You must cause any modified files to carry prominent notices
|
||||
stating that You changed the files; and
|
||||
|
||||
(c) You must retain, in the Source form of any Derivative Works
|
||||
that You distribute, all copyright, patent, trademark, and
|
||||
attribution notices from the Source form of the Work,
|
||||
excluding those notices that do not pertain to any part of
|
||||
the Derivative Works; and
|
||||
|
||||
(d) If the Work includes a "NOTICE" text file as part of its
|
||||
distribution, then any Derivative Works that You distribute must
|
||||
include a readable copy of the attribution notices contained
|
||||
within such NOTICE file, excluding those notices that do not
|
||||
pertain to any part of the Derivative Works, in at least one
|
||||
of the following places: within a NOTICE text file distributed
|
||||
as part of the Derivative Works; within the Source form or
|
||||
documentation, if provided along with the Derivative Works; or,
|
||||
within a display generated by the Derivative Works, if and
|
||||
wherever such third-party notices normally appear. The contents
|
||||
of the NOTICE file are for informational purposes only and
|
||||
do not modify the License. You may add Your own attribution
|
||||
notices within Derivative Works that You distribute, alongside
|
||||
or as an addendum to the NOTICE text from the Work, provided
|
||||
that such additional attribution notices cannot be construed
|
||||
as modifying the License.
|
||||
|
||||
You may add Your own copyright statement to Your modifications and
|
||||
may provide additional or different license terms and conditions
|
||||
for use, reproduction, or distribution of Your modifications, or
|
||||
for any such Derivative Works as a whole, provided Your use,
|
||||
reproduction, and distribution of the Work otherwise complies with
|
||||
the conditions stated in this License.
|
||||
|
||||
5. Submission of Contributions. Unless You explicitly state otherwise,
|
||||
any Contribution intentionally submitted for inclusion in the Work
|
||||
by You to the Licensor shall be under the terms and conditions of
|
||||
this License, without any additional terms or conditions.
|
||||
Notwithstanding the above, nothing herein shall supersede or modify
|
||||
the terms of any separate license agreement you may have executed
|
||||
with Licensor regarding such Contributions.
|
||||
|
||||
6. Trademarks. This License does not grant permission to use the trade
|
||||
names, trademarks, service marks, or product names of the Licensor,
|
||||
except as required for reasonable and customary use in describing the
|
||||
origin of the Work and reproducing the content of the NOTICE file.
|
||||
|
||||
7. Disclaimer of Warranty. Unless required by applicable law or
|
||||
agreed to in writing, Licensor provides the Work (and each
|
||||
Contributor provides its Contributions) on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
|
||||
implied, including, without limitation, any warranties or conditions
|
||||
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
|
||||
PARTICULAR PURPOSE. You are solely responsible for determining the
|
||||
appropriateness of using or redistributing the Work and assume any
|
||||
risks associated with Your exercise of permissions under this License.
|
||||
|
||||
8. Limitation of Liability. In no event and under no legal theory,
|
||||
whether in tort (including negligence), contract, or otherwise,
|
||||
unless required by applicable law (such as deliberate and grossly
|
||||
negligent acts) or agreed to in writing, shall any Contributor be
|
||||
liable to You for damages, including any direct, indirect, special,
|
||||
incidental, or consequential damages of any character arising as a
|
||||
result of this License or out of the use or inability to use the
|
||||
Work (including but not limited to damages for loss of goodwill,
|
||||
work stoppage, computer failure or malfunction, or any and all
|
||||
other commercial damages or losses), even if such Contributor
|
||||
has been advised of the possibility of such damages.
|
||||
|
||||
9. Accepting Warranty or Additional Liability. While redistributing
|
||||
the Work or Derivative Works thereof, You may choose to offer,
|
||||
and charge a fee for, acceptance of support, warranty, indemnity,
|
||||
or other liability obligations and/or rights consistent with this
|
||||
License. However, in accepting such obligations, You may act only
|
||||
on Your own behalf and on Your sole responsibility, not on behalf
|
||||
of any other Contributor, and only if You agree to indemnify,
|
||||
defend, and hold each Contributor harmless for any liability
|
||||
incurred by, or claims asserted against, such Contributor by reason
|
||||
of your accepting any such warranty or additional liability.
|
||||
|
||||
END OF TERMS AND CONDITIONS
|
||||
|
||||
APPENDIX: How to apply the Apache License to your work.
|
||||
|
||||
To apply the Apache License to your work, attach the following
|
||||
boilerplate notice, with the fields enclosed by brackets "[]"
|
||||
replaced with your own identifying information. (Don't include
|
||||
the brackets!) The text should be enclosed in the appropriate
|
||||
comment syntax for the file format. We also recommend that a
|
||||
file or class name and description of purpose be included on the
|
||||
same "printed page" as the copyright notice for easier
|
||||
identification within third-party archives.
|
||||
|
||||
Copyright [yyyy] [name of copyright owner]
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
|
@ -1,277 +0,0 @@
|
|||
// Copyright 2016 Google LLC
|
||||
//
|
||||
// Licensed under the Apache License, Version 2.0 (the "License");
|
||||
// you may not use this file except in compliance with the License.
|
||||
// You may obtain a copy of the License at
|
||||
//
|
||||
// http://www.apache.org/licenses/LICENSE-2.0
|
||||
//
|
||||
// Unless required by applicable law or agreed to in writing, software
|
||||
// distributed under the License is distributed on an "AS IS" BASIS,
|
||||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
// Package civil implements types for civil time, a time-zone-independent
|
||||
// representation of time that follows the rules of the proleptic
|
||||
// Gregorian calendar with exactly 24-hour days, 60-minute hours, and 60-second
|
||||
// minutes.
|
||||
//
|
||||
// Because they lack location information, these types do not represent unique
|
||||
// moments or intervals of time. Use time.Time for that purpose.
|
||||
package civil
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
// A Date represents a date (year, month, day).
|
||||
//
|
||||
// This type does not include location information, and therefore does not
|
||||
// describe a unique 24-hour timespan.
|
||||
type Date struct {
|
||||
Year int // Year (e.g., 2014).
|
||||
Month time.Month // Month of the year (January = 1, ...).
|
||||
Day int // Day of the month, starting at 1.
|
||||
}
|
||||
|
||||
// DateOf returns the Date in which a time occurs in that time's location.
|
||||
func DateOf(t time.Time) Date {
|
||||
var d Date
|
||||
d.Year, d.Month, d.Day = t.Date()
|
||||
return d
|
||||
}
|
||||
|
||||
// ParseDate parses a string in RFC3339 full-date format and returns the date value it represents.
|
||||
func ParseDate(s string) (Date, error) {
|
||||
t, err := time.Parse("2006-01-02", s)
|
||||
if err != nil {
|
||||
return Date{}, err
|
||||
}
|
||||
return DateOf(t), nil
|
||||
}
|
||||
|
||||
// String returns the date in RFC3339 full-date format.
|
||||
func (d Date) String() string {
|
||||
return fmt.Sprintf("%04d-%02d-%02d", d.Year, d.Month, d.Day)
|
||||
}
|
||||
|
||||
// IsValid reports whether the date is valid.
|
||||
func (d Date) IsValid() bool {
|
||||
return DateOf(d.In(time.UTC)) == d
|
||||
}
|
||||
|
||||
// In returns the time corresponding to time 00:00:00 of the date in the location.
|
||||
//
|
||||
// In is always consistent with time.Date, even when time.Date returns a time
|
||||
// on a different day. For example, if loc is America/Indiana/Vincennes, then both
|
||||
// time.Date(1955, time.May, 1, 0, 0, 0, 0, loc)
|
||||
// and
|
||||
// civil.Date{Year: 1955, Month: time.May, Day: 1}.In(loc)
|
||||
// return 23:00:00 on April 30, 1955.
|
||||
//
|
||||
// In panics if loc is nil.
|
||||
func (d Date) In(loc *time.Location) time.Time {
|
||||
return time.Date(d.Year, d.Month, d.Day, 0, 0, 0, 0, loc)
|
||||
}
|
||||
|
||||
// AddDays returns the date that is n days in the future.
|
||||
// n can also be negative to go into the past.
|
||||
func (d Date) AddDays(n int) Date {
|
||||
return DateOf(d.In(time.UTC).AddDate(0, 0, n))
|
||||
}
|
||||
|
||||
// DaysSince returns the signed number of days between the date and s, not including the end day.
|
||||
// This is the inverse operation to AddDays.
|
||||
func (d Date) DaysSince(s Date) (days int) {
|
||||
// We convert to Unix time so we do not have to worry about leap seconds:
|
||||
// Unix time increases by exactly 86400 seconds per day.
|
||||
deltaUnix := d.In(time.UTC).Unix() - s.In(time.UTC).Unix()
|
||||
return int(deltaUnix / 86400)
|
||||
}
|
||||
|
||||
// Before reports whether d1 occurs before d2.
|
||||
func (d1 Date) Before(d2 Date) bool {
|
||||
if d1.Year != d2.Year {
|
||||
return d1.Year < d2.Year
|
||||
}
|
||||
if d1.Month != d2.Month {
|
||||
return d1.Month < d2.Month
|
||||
}
|
||||
return d1.Day < d2.Day
|
||||
}
|
||||
|
||||
// After reports whether d1 occurs after d2.
|
||||
func (d1 Date) After(d2 Date) bool {
|
||||
return d2.Before(d1)
|
||||
}
|
||||
|
||||
// MarshalText implements the encoding.TextMarshaler interface.
|
||||
// The output is the result of d.String().
|
||||
func (d Date) MarshalText() ([]byte, error) {
|
||||
return []byte(d.String()), nil
|
||||
}
|
||||
|
||||
// UnmarshalText implements the encoding.TextUnmarshaler interface.
|
||||
// The date is expected to be a string in a format accepted by ParseDate.
|
||||
func (d *Date) UnmarshalText(data []byte) error {
|
||||
var err error
|
||||
*d, err = ParseDate(string(data))
|
||||
return err
|
||||
}
|
||||
|
||||
// A Time represents a time with nanosecond precision.
|
||||
//
|
||||
// This type does not include location information, and therefore does not
|
||||
// describe a unique moment in time.
|
||||
//
|
||||
// This type exists to represent the TIME type in storage-based APIs like BigQuery.
|
||||
// Most operations on Times are unlikely to be meaningful. Prefer the DateTime type.
|
||||
type Time struct {
|
||||
Hour int // The hour of the day in 24-hour format; range [0-23]
|
||||
Minute int // The minute of the hour; range [0-59]
|
||||
Second int // The second of the minute; range [0-59]
|
||||
Nanosecond int // The nanosecond of the second; range [0-999999999]
|
||||
}
|
||||
|
||||
// TimeOf returns the Time representing the time of day in which a time occurs
|
||||
// in that time's location. It ignores the date.
|
||||
func TimeOf(t time.Time) Time {
|
||||
var tm Time
|
||||
tm.Hour, tm.Minute, tm.Second = t.Clock()
|
||||
tm.Nanosecond = t.Nanosecond()
|
||||
return tm
|
||||
}
|
||||
|
||||
// ParseTime parses a string and returns the time value it represents.
|
||||
// ParseTime accepts an extended form of the RFC3339 partial-time format. After
|
||||
// the HH:MM:SS part of the string, an optional fractional part may appear,
|
||||
// consisting of a decimal point followed by one to nine decimal digits.
|
||||
// (RFC3339 admits only one digit after the decimal point).
|
||||
func ParseTime(s string) (Time, error) {
|
||||
t, err := time.Parse("15:04:05.999999999", s)
|
||||
if err != nil {
|
||||
return Time{}, err
|
||||
}
|
||||
return TimeOf(t), nil
|
||||
}
|
||||
|
||||
// String returns the date in the format described in ParseTime. If Nanoseconds
|
||||
// is zero, no fractional part will be generated. Otherwise, the result will
|
||||
// end with a fractional part consisting of a decimal point and nine digits.
|
||||
func (t Time) String() string {
|
||||
s := fmt.Sprintf("%02d:%02d:%02d", t.Hour, t.Minute, t.Second)
|
||||
if t.Nanosecond == 0 {
|
||||
return s
|
||||
}
|
||||
return s + fmt.Sprintf(".%09d", t.Nanosecond)
|
||||
}
|
||||
|
||||
// IsValid reports whether the time is valid.
|
||||
func (t Time) IsValid() bool {
|
||||
// Construct a non-zero time.
|
||||
tm := time.Date(2, 2, 2, t.Hour, t.Minute, t.Second, t.Nanosecond, time.UTC)
|
||||
return TimeOf(tm) == t
|
||||
}
|
||||
|
||||
// MarshalText implements the encoding.TextMarshaler interface.
|
||||
// The output is the result of t.String().
|
||||
func (t Time) MarshalText() ([]byte, error) {
|
||||
return []byte(t.String()), nil
|
||||
}
|
||||
|
||||
// UnmarshalText implements the encoding.TextUnmarshaler interface.
|
||||
// The time is expected to be a string in a format accepted by ParseTime.
|
||||
func (t *Time) UnmarshalText(data []byte) error {
|
||||
var err error
|
||||
*t, err = ParseTime(string(data))
|
||||
return err
|
||||
}
|
||||
|
||||
// A DateTime represents a date and time.
|
||||
//
|
||||
// This type does not include location information, and therefore does not
|
||||
// describe a unique moment in time.
|
||||
type DateTime struct {
|
||||
Date Date
|
||||
Time Time
|
||||
}
|
||||
|
||||
// Note: We deliberately do not embed Date into DateTime, to avoid promoting AddDays and Sub.
|
||||
|
||||
// DateTimeOf returns the DateTime in which a time occurs in that time's location.
|
||||
func DateTimeOf(t time.Time) DateTime {
|
||||
return DateTime{
|
||||
Date: DateOf(t),
|
||||
Time: TimeOf(t),
|
||||
}
|
||||
}
|
||||
|
||||
// ParseDateTime parses a string and returns the DateTime it represents.
|
||||
// ParseDateTime accepts a variant of the RFC3339 date-time format that omits
|
||||
// the time offset but includes an optional fractional time, as described in
|
||||
// ParseTime. Informally, the accepted format is
|
||||
// YYYY-MM-DDTHH:MM:SS[.FFFFFFFFF]
|
||||
// where the 'T' may be a lower-case 't'.
|
||||
func ParseDateTime(s string) (DateTime, error) {
|
||||
t, err := time.Parse("2006-01-02T15:04:05.999999999", s)
|
||||
if err != nil {
|
||||
t, err = time.Parse("2006-01-02t15:04:05.999999999", s)
|
||||
if err != nil {
|
||||
return DateTime{}, err
|
||||
}
|
||||
}
|
||||
return DateTimeOf(t), nil
|
||||
}
|
||||
|
||||
// String returns the date in the format described in ParseDate.
|
||||
func (dt DateTime) String() string {
|
||||
return dt.Date.String() + "T" + dt.Time.String()
|
||||
}
|
||||
|
||||
// IsValid reports whether the datetime is valid.
|
||||
func (dt DateTime) IsValid() bool {
|
||||
return dt.Date.IsValid() && dt.Time.IsValid()
|
||||
}
|
||||
|
||||
// In returns the time corresponding to the DateTime in the given location.
|
||||
//
|
||||
// If the time is missing or ambigous at the location, In returns the same
|
||||
// result as time.Date. For example, if loc is America/Indiana/Vincennes, then
|
||||
// both
|
||||
// time.Date(1955, time.May, 1, 0, 30, 0, 0, loc)
|
||||
// and
|
||||
// civil.DateTime{
|
||||
// civil.Date{Year: 1955, Month: time.May, Day: 1}},
|
||||
// civil.Time{Minute: 30}}.In(loc)
|
||||
// return 23:30:00 on April 30, 1955.
|
||||
//
|
||||
// In panics if loc is nil.
|
||||
func (dt DateTime) In(loc *time.Location) time.Time {
|
||||
return time.Date(dt.Date.Year, dt.Date.Month, dt.Date.Day, dt.Time.Hour, dt.Time.Minute, dt.Time.Second, dt.Time.Nanosecond, loc)
|
||||
}
|
||||
|
||||
// Before reports whether dt1 occurs before dt2.
|
||||
func (dt1 DateTime) Before(dt2 DateTime) bool {
|
||||
return dt1.In(time.UTC).Before(dt2.In(time.UTC))
|
||||
}
|
||||
|
||||
// After reports whether dt1 occurs after dt2.
|
||||
func (dt1 DateTime) After(dt2 DateTime) bool {
|
||||
return dt2.Before(dt1)
|
||||
}
|
||||
|
||||
// MarshalText implements the encoding.TextMarshaler interface.
|
||||
// The output is the result of dt.String().
|
||||
func (dt DateTime) MarshalText() ([]byte, error) {
|
||||
return []byte(dt.String()), nil
|
||||
}
|
||||
|
||||
// UnmarshalText implements the encoding.TextUnmarshaler interface.
|
||||
// The datetime is expected to be a string in a format accepted by ParseDateTime
|
||||
func (dt *DateTime) UnmarshalText(data []byte) error {
|
||||
var err error
|
||||
*dt, err = ParseDateTime(string(data))
|
||||
return err
|
||||
}
|
|
@ -1,3 +0,0 @@
|
|||
/examples/blog/blog
|
||||
/examples/orders/orders
|
||||
/examples/basic/basic
|
|
@ -1,25 +0,0 @@
|
|||
language: go
|
||||
|
||||
go_import_path: github.com/DATA-DOG/go-sqlmock
|
||||
|
||||
go:
|
||||
- 1.2.x
|
||||
- 1.3.x
|
||||
- 1.4 # has no cover tool for latest releases
|
||||
- 1.5.x
|
||||
- 1.6.x
|
||||
- 1.7.x
|
||||
- 1.8.x
|
||||
- 1.9.x
|
||||
- 1.10.x
|
||||
- 1.11.x
|
||||
|
||||
sudo: false
|
||||
|
||||
script:
|
||||
- go vet
|
||||
- test -z "$(go fmt ./...)" # fail if not formatted properly
|
||||
- go test -race -coverprofile=coverage.txt -covermode=atomic
|
||||
|
||||
after_success:
|
||||
- bash <(curl -s https://codecov.io/bash)
|
|
@ -1,28 +0,0 @@
|
|||
The three clause BSD license (http://en.wikipedia.org/wiki/BSD_licenses)
|
||||
|
||||
Copyright (c) 2013-2019, DATA-DOG team
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
this list of conditions and the following disclaimer in the documentation
|
||||
and/or other materials provided with the distribution.
|
||||
|
||||
* The name DataDog.lt may not be used to endorse or promote products
|
||||
derived from this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL MICHAEL BOSTOCK BE LIABLE FOR ANY DIRECT,
|
||||
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
|
||||
BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY
|
||||
OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
||||
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
||||
EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@ -1,259 +0,0 @@
|
|||
[![Build Status](https://travis-ci.org/DATA-DOG/go-sqlmock.svg)](https://travis-ci.org/DATA-DOG/go-sqlmock)
|
||||
[![GoDoc](https://godoc.org/github.com/DATA-DOG/go-sqlmock?status.svg)](https://godoc.org/github.com/DATA-DOG/go-sqlmock)
|
||||
[![Go Report Card](https://goreportcard.com/badge/github.com/DATA-DOG/go-sqlmock)](https://goreportcard.com/report/github.com/DATA-DOG/go-sqlmock)
|
||||
[![codecov.io](https://codecov.io/github/DATA-DOG/go-sqlmock/branch/master/graph/badge.svg)](https://codecov.io/github/DATA-DOG/go-sqlmock)
|
||||
|
||||
# Sql driver mock for Golang
|
||||
|
||||
**sqlmock** is a mock library implementing [sql/driver](https://godoc.org/database/sql/driver). Which has one and only
|
||||
purpose - to simulate any **sql** driver behavior in tests, without needing a real database connection. It helps to
|
||||
maintain correct **TDD** workflow.
|
||||
|
||||
- this library is now complete and stable. (you may not find new changes for this reason)
|
||||
- supports concurrency and multiple connections.
|
||||
- supports **go1.8** Context related feature mocking and Named sql parameters.
|
||||
- does not require any modifications to your source code.
|
||||
- the driver allows to mock any sql driver method behavior.
|
||||
- has strict by default expectation order matching.
|
||||
- has no third party dependencies.
|
||||
|
||||
**NOTE:** in **v1.2.0** **sqlmock.Rows** has changed to struct from interface, if you were using any type references to that
|
||||
interface, you will need to switch it to a pointer struct type. Also, **sqlmock.Rows** were used to implement **driver.Rows**
|
||||
interface, which was not required or useful for mocking and was removed. Hope it will not cause issues.
|
||||
|
||||
## Install
|
||||
|
||||
go get github.com/DATA-DOG/go-sqlmock
|
||||
|
||||
## Documentation and Examples
|
||||
|
||||
Visit [godoc](http://godoc.org/github.com/DATA-DOG/go-sqlmock) for general examples and public api reference.
|
||||
See **.travis.yml** for supported **go** versions.
|
||||
Different use case, is to functionally test with a real database - [go-txdb](https://github.com/DATA-DOG/go-txdb)
|
||||
all database related actions are isolated within a single transaction so the database can remain in the same state.
|
||||
|
||||
See implementation examples:
|
||||
|
||||
- [blog API server](https://github.com/DATA-DOG/go-sqlmock/tree/master/examples/blog)
|
||||
- [the same orders example](https://github.com/DATA-DOG/go-sqlmock/tree/master/examples/orders)
|
||||
|
||||
### Something you may want to test, assuming you use the [go-mysql-driver](https://github.com/go-sql-driver/mysql)
|
||||
|
||||
``` go
|
||||
package main
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
|
||||
_ "github.com/go-sql-driver/mysql"
|
||||
)
|
||||
|
||||
func recordStats(db *sql.DB, userID, productID int64) (err error) {
|
||||
tx, err := db.Begin()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
defer func() {
|
||||
switch err {
|
||||
case nil:
|
||||
err = tx.Commit()
|
||||
default:
|
||||
tx.Rollback()
|
||||
}
|
||||
}()
|
||||
|
||||
if _, err = tx.Exec("UPDATE products SET views = views + 1"); err != nil {
|
||||
return
|
||||
}
|
||||
if _, err = tx.Exec("INSERT INTO product_viewers (user_id, product_id) VALUES (?, ?)", userID, productID); err != nil {
|
||||
return
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
func main() {
|
||||
// @NOTE: the real connection is not required for tests
|
||||
db, err := sql.Open("mysql", "root@/blog")
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
if err = recordStats(db, 1 /*some user id*/, 5 /*some product id*/); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Tests with sqlmock
|
||||
|
||||
``` go
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"testing"
|
||||
|
||||
"github.com/DATA-DOG/go-sqlmock"
|
||||
)
|
||||
|
||||
// a successful case
|
||||
func TestShouldUpdateStats(t *testing.T) {
|
||||
db, mock, err := sqlmock.New()
|
||||
if err != nil {
|
||||
t.Fatalf("an error '%s' was not expected when opening a stub database connection", err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
mock.ExpectBegin()
|
||||
mock.ExpectExec("UPDATE products").WillReturnResult(sqlmock.NewResult(1, 1))
|
||||
mock.ExpectExec("INSERT INTO product_viewers").WithArgs(2, 3).WillReturnResult(sqlmock.NewResult(1, 1))
|
||||
mock.ExpectCommit()
|
||||
|
||||
// now we execute our method
|
||||
if err = recordStats(db, 2, 3); err != nil {
|
||||
t.Errorf("error was not expected while updating stats: %s", err)
|
||||
}
|
||||
|
||||
// we make sure that all expectations were met
|
||||
if err := mock.ExpectationsWereMet(); err != nil {
|
||||
t.Errorf("there were unfulfilled expectations: %s", err)
|
||||
}
|
||||
}
|
||||
|
||||
// a failing test case
|
||||
func TestShouldRollbackStatUpdatesOnFailure(t *testing.T) {
|
||||
db, mock, err := sqlmock.New()
|
||||
if err != nil {
|
||||
t.Fatalf("an error '%s' was not expected when opening a stub database connection", err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
mock.ExpectBegin()
|
||||
mock.ExpectExec("UPDATE products").WillReturnResult(sqlmock.NewResult(1, 1))
|
||||
mock.ExpectExec("INSERT INTO product_viewers").
|
||||
WithArgs(2, 3).
|
||||
WillReturnError(fmt.Errorf("some error"))
|
||||
mock.ExpectRollback()
|
||||
|
||||
// now we execute our method
|
||||
if err = recordStats(db, 2, 3); err == nil {
|
||||
t.Errorf("was expecting an error, but there was none")
|
||||
}
|
||||
|
||||
// we make sure that all expectations were met
|
||||
if err := mock.ExpectationsWereMet(); err != nil {
|
||||
t.Errorf("there were unfulfilled expectations: %s", err)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
## Customize SQL query matching
|
||||
|
||||
There were plenty of requests from users regarding SQL query string validation or different matching option.
|
||||
We have now implemented the `QueryMatcher` interface, which can be passed through an option when calling
|
||||
`sqlmock.New` or `sqlmock.NewWithDSN`.
|
||||
|
||||
This now allows to include some library, which would allow for example to parse and validate `mysql` SQL AST.
|
||||
And create a custom QueryMatcher in order to validate SQL in sophisticated ways.
|
||||
|
||||
By default, **sqlmock** is preserving backward compatibility and default query matcher is `sqlmock.QueryMatcherRegexp`
|
||||
which uses expected SQL string as a regular expression to match incoming query string. There is an equality matcher:
|
||||
`QueryMatcherEqual` which will do a full case sensitive match.
|
||||
|
||||
In order to customize the QueryMatcher, use the following:
|
||||
|
||||
``` go
|
||||
db, mock, err := sqlmock.New(sqlmock.QueryMatcherOption(sqlmock.QueryMatcherEqual))
|
||||
```
|
||||
|
||||
The query matcher can be fully customized based on user needs. **sqlmock** will not
|
||||
provide a standard sql parsing matchers, since various drivers may not follow the same SQL standard.
|
||||
|
||||
## Matching arguments like time.Time
|
||||
|
||||
There may be arguments which are of `struct` type and cannot be compared easily by value like `time.Time`. In this case
|
||||
**sqlmock** provides an [Argument](https://godoc.org/github.com/DATA-DOG/go-sqlmock#Argument) interface which
|
||||
can be used in more sophisticated matching. Here is a simple example of time argument matching:
|
||||
|
||||
``` go
|
||||
type AnyTime struct{}
|
||||
|
||||
// Match satisfies sqlmock.Argument interface
|
||||
func (a AnyTime) Match(v driver.Value) bool {
|
||||
_, ok := v.(time.Time)
|
||||
return ok
|
||||
}
|
||||
|
||||
func TestAnyTimeArgument(t *testing.T) {
|
||||
t.Parallel()
|
||||
db, mock, err := New()
|
||||
if err != nil {
|
||||
t.Errorf("an error '%s' was not expected when opening a stub database connection", err)
|
||||
}
|
||||
defer db.Close()
|
||||
|
||||
mock.ExpectExec("INSERT INTO users").
|
||||
WithArgs("john", AnyTime{}).
|
||||
WillReturnResult(NewResult(1, 1))
|
||||
|
||||
_, err = db.Exec("INSERT INTO users(name, created_at) VALUES (?, ?)", "john", time.Now())
|
||||
if err != nil {
|
||||
t.Errorf("error '%s' was not expected, while inserting a row", err)
|
||||
}
|
||||
|
||||
if err := mock.ExpectationsWereMet(); err != nil {
|
||||
t.Errorf("there were unfulfilled expectations: %s", err)
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
It only asserts that argument is of `time.Time` type.
|
||||
|
||||
## Run tests
|
||||
|
||||
go test -race
|
||||
|
||||
## Change Log
|
||||
|
||||
- **2019-02-13** - added `go.mod` removed the references and suggestions using `gopkg.in`.
|
||||
- **2018-12-11** - added expectation of Rows to be closed, while mocking expected query.
|
||||
- **2018-12-11** - introduced an option to provide **QueryMatcher** in order to customize SQL query matching.
|
||||
- **2017-09-01** - it is now possible to expect that prepared statement will be closed,
|
||||
using **ExpectedPrepare.WillBeClosed**.
|
||||
- **2017-02-09** - implemented support for **go1.8** features. **Rows** interface was changed to struct
|
||||
but contains all methods as before and should maintain backwards compatibility. **ExpectedQuery.WillReturnRows** may now
|
||||
accept multiple row sets.
|
||||
- **2016-11-02** - `db.Prepare()` was not validating expected prepare SQL
|
||||
query. It should still be validated even if Exec or Query is not
|
||||
executed on that prepared statement.
|
||||
- **2016-02-23** - added **sqlmock.AnyArg()** function to provide any kind
|
||||
of argument matcher.
|
||||
- **2016-02-23** - convert expected arguments to driver.Value as natural
|
||||
driver does, the change may affect time.Time comparison and will be
|
||||
stricter. See [issue](https://github.com/DATA-DOG/go-sqlmock/issues/31).
|
||||
- **2015-08-27** - **v1** api change, concurrency support, all known issues fixed.
|
||||
- **2014-08-16** instead of **panic** during reflect type mismatch when comparing query arguments - now return error
|
||||
- **2014-08-14** added **sqlmock.NewErrorResult** which gives an option to return driver.Result with errors for
|
||||
interface methods, see [issue](https://github.com/DATA-DOG/go-sqlmock/issues/5)
|
||||
- **2014-05-29** allow to match arguments in more sophisticated ways, by providing an **sqlmock.Argument** interface
|
||||
- **2014-04-21** introduce **sqlmock.New()** to open a mock database connection for tests. This method
|
||||
calls sql.DB.Ping to ensure that connection is open, see [issue](https://github.com/DATA-DOG/go-sqlmock/issues/4).
|
||||
This way on Close it will surely assert if all expectations are met, even if database was not triggered at all.
|
||||
The old way is still available, but it is advisable to call db.Ping manually before asserting with db.Close.
|
||||
- **2014-02-14** RowsFromCSVString is now a part of Rows interface named as FromCSVString.
|
||||
It has changed to allow more ways to construct rows and to easily extend this API in future.
|
||||
See [issue 1](https://github.com/DATA-DOG/go-sqlmock/issues/1)
|
||||
**RowsFromCSVString** is deprecated and will be removed in future
|
||||
|
||||
## Contributions
|
||||
|
||||
Feel free to open a pull request. Note, if you wish to contribute an extension to public (exported methods or types) -
|
||||
please open an issue before, to discuss whether these changes can be accepted. All backward incompatible changes are
|
||||
and will be treated cautiously
|
||||
|
||||
## License
|
||||
|
||||
The [three clause BSD license](http://en.wikipedia.org/wiki/BSD_licenses)
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
package sqlmock
|
||||
|
||||
import "database/sql/driver"
|
||||
|
||||
// Argument interface allows to match
|
||||
// any argument in specific way when used with
|
||||
// ExpectedQuery and ExpectedExec expectations.
|
||||
type Argument interface {
|
||||
Match(driver.Value) bool
|
||||
}
|
||||
|
||||
// AnyArg will return an Argument which can
|
||||
// match any kind of arguments.
|
||||
//
|
||||
// Useful for time.Time or similar kinds of arguments.
|
||||
func AnyArg() Argument {
|
||||
return anyArgument{}
|
||||
}
|
||||
|
||||
type anyArgument struct{}
|
||||
|
||||
func (a anyArgument) Match(_ driver.Value) bool {
|
||||
return true
|
||||
}
|
|
@ -1,81 +0,0 @@
|
|||
package sqlmock
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
"sync"
|
||||
)
|
||||
|
||||
var pool *mockDriver
|
||||
|
||||
func init() {
|
||||
pool = &mockDriver{
|
||||
conns: make(map[string]*sqlmock),
|
||||
}
|
||||
sql.Register("sqlmock", pool)
|
||||
}
|
||||
|
||||
type mockDriver struct {
|
||||
sync.Mutex
|
||||
counter int
|
||||
conns map[string]*sqlmock
|
||||
}
|
||||
|
||||
func (d *mockDriver) Open(dsn string) (driver.Conn, error) {
|
||||
d.Lock()
|
||||
defer d.Unlock()
|
||||
|
||||
c, ok := d.conns[dsn]
|
||||
if !ok {
|
||||
return c, fmt.Errorf("expected a connection to be available, but it is not")
|
||||
}
|
||||
|
||||
c.opened++
|
||||
return c, nil
|
||||
}
|
||||
|
||||
// New creates sqlmock database connection and a mock to manage expectations.
|
||||
// Accepts options, like ValueConverterOption, to use a ValueConverter from
|
||||
// a specific driver.
|
||||
// Pings db so that all expectations could be
|
||||
// asserted.
|
||||
func New(options ...func(*sqlmock) error) (*sql.DB, Sqlmock, error) {
|
||||
pool.Lock()
|
||||
dsn := fmt.Sprintf("sqlmock_db_%d", pool.counter)
|
||||
pool.counter++
|
||||
|
||||
smock := &sqlmock{dsn: dsn, drv: pool, ordered: true}
|
||||
pool.conns[dsn] = smock
|
||||
pool.Unlock()
|
||||
|
||||
return smock.open(options)
|
||||
}
|
||||
|
||||
// NewWithDSN creates sqlmock database connection with a specific DSN
|
||||
// and a mock to manage expectations.
|
||||
// Accepts options, like ValueConverterOption, to use a ValueConverter from
|
||||
// a specific driver.
|
||||
// Pings db so that all expectations could be asserted.
|
||||
//
|
||||
// This method is introduced because of sql abstraction
|
||||
// libraries, which do not provide a way to initialize
|
||||
// with sql.DB instance. For example GORM library.
|
||||
//
|
||||
// Note, it will error if attempted to create with an
|
||||
// already used dsn
|
||||
//
|
||||
// It is not recommended to use this method, unless you
|
||||
// really need it and there is no other way around.
|
||||
func NewWithDSN(dsn string, options ...func(*sqlmock) error) (*sql.DB, Sqlmock, error) {
|
||||
pool.Lock()
|
||||
if _, ok := pool.conns[dsn]; ok {
|
||||
pool.Unlock()
|
||||
return nil, nil, fmt.Errorf("cannot create a new mock database with the same dsn: %s", dsn)
|
||||
}
|
||||
smock := &sqlmock{dsn: dsn, drv: pool, ordered: true}
|
||||
pool.conns[dsn] = smock
|
||||
pool.Unlock()
|
||||
|
||||
return smock.open(options)
|
||||
}
|
|
@ -1,355 +0,0 @@
|
|||
package sqlmock
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
"strings"
|
||||
"sync"
|
||||
"time"
|
||||
)
|
||||
|
||||
// an expectation interface
|
||||
type expectation interface {
|
||||
fulfilled() bool
|
||||
Lock()
|
||||
Unlock()
|
||||
String() string
|
||||
}
|
||||
|
||||
// common expectation struct
|
||||
// satisfies the expectation interface
|
||||
type commonExpectation struct {
|
||||
sync.Mutex
|
||||
triggered bool
|
||||
err error
|
||||
}
|
||||
|
||||
func (e *commonExpectation) fulfilled() bool {
|
||||
return e.triggered
|
||||
}
|
||||
|
||||
// ExpectedClose is used to manage *sql.DB.Close expectation
|
||||
// returned by *Sqlmock.ExpectClose.
|
||||
type ExpectedClose struct {
|
||||
commonExpectation
|
||||
}
|
||||
|
||||
// WillReturnError allows to set an error for *sql.DB.Close action
|
||||
func (e *ExpectedClose) WillReturnError(err error) *ExpectedClose {
|
||||
e.err = err
|
||||
return e
|
||||
}
|
||||
|
||||
// String returns string representation
|
||||
func (e *ExpectedClose) String() string {
|
||||
msg := "ExpectedClose => expecting database Close"
|
||||
if e.err != nil {
|
||||
msg += fmt.Sprintf(", which should return error: %s", e.err)
|
||||
}
|
||||
return msg
|
||||
}
|
||||
|
||||
// ExpectedBegin is used to manage *sql.DB.Begin expectation
|
||||
// returned by *Sqlmock.ExpectBegin.
|
||||
type ExpectedBegin struct {
|
||||
commonExpectation
|
||||
delay time.Duration
|
||||
}
|
||||
|
||||
// WillReturnError allows to set an error for *sql.DB.Begin action
|
||||
func (e *ExpectedBegin) WillReturnError(err error) *ExpectedBegin {
|
||||
e.err = err
|
||||
return e
|
||||
}
|
||||
|
||||
// String returns string representation
|
||||
func (e *ExpectedBegin) String() string {
|
||||
msg := "ExpectedBegin => expecting database transaction Begin"
|
||||
if e.err != nil {
|
||||
msg += fmt.Sprintf(", which should return error: %s", e.err)
|
||||
}
|
||||
return msg
|
||||
}
|
||||
|
||||
// WillDelayFor allows to specify duration for which it will delay
|
||||
// result. May be used together with Context
|
||||
func (e *ExpectedBegin) WillDelayFor(duration time.Duration) *ExpectedBegin {
|
||||
e.delay = duration
|
||||
return e
|
||||
}
|
||||
|
||||
// ExpectedCommit is used to manage *sql.Tx.Commit expectation
|
||||
// returned by *Sqlmock.ExpectCommit.
|
||||
type ExpectedCommit struct {
|
||||
commonExpectation
|
||||
}
|
||||
|
||||
// WillReturnError allows to set an error for *sql.Tx.Close action
|
||||
func (e *ExpectedCommit) WillReturnError(err error) *ExpectedCommit {
|
||||
e.err = err
|
||||
return e
|
||||
}
|
||||
|
||||
// String returns string representation
|
||||
func (e *ExpectedCommit) String() string {
|
||||
msg := "ExpectedCommit => expecting transaction Commit"
|
||||
if e.err != nil {
|
||||
msg += fmt.Sprintf(", which should return error: %s", e.err)
|
||||
}
|
||||
return msg
|
||||
}
|
||||
|
||||
// ExpectedRollback is used to manage *sql.Tx.Rollback expectation
|
||||
// returned by *Sqlmock.ExpectRollback.
|
||||
type ExpectedRollback struct {
|
||||
commonExpectation
|
||||
}
|
||||
|
||||
// WillReturnError allows to set an error for *sql.Tx.Rollback action
|
||||
func (e *ExpectedRollback) WillReturnError(err error) *ExpectedRollback {
|
||||
e.err = err
|
||||
return e
|
||||
}
|
||||
|
||||
// String returns string representation
|
||||
func (e *ExpectedRollback) String() string {
|
||||
msg := "ExpectedRollback => expecting transaction Rollback"
|
||||
if e.err != nil {
|
||||
msg += fmt.Sprintf(", which should return error: %s", e.err)
|
||||
}
|
||||
return msg
|
||||
}
|
||||
|
||||
// ExpectedQuery is used to manage *sql.DB.Query, *dql.DB.QueryRow, *sql.Tx.Query,
|
||||
// *sql.Tx.QueryRow, *sql.Stmt.Query or *sql.Stmt.QueryRow expectations.
|
||||
// Returned by *Sqlmock.ExpectQuery.
|
||||
type ExpectedQuery struct {
|
||||
queryBasedExpectation
|
||||
rows driver.Rows
|
||||
delay time.Duration
|
||||
rowsMustBeClosed bool
|
||||
rowsWereClosed bool
|
||||
}
|
||||
|
||||
// WithArgs will match given expected args to actual database query arguments.
|
||||
// if at least one argument does not match, it will return an error. For specific
|
||||
// arguments an sqlmock.Argument interface can be used to match an argument.
|
||||
func (e *ExpectedQuery) WithArgs(args ...driver.Value) *ExpectedQuery {
|
||||
e.args = args
|
||||
return e
|
||||
}
|
||||
|
||||
// RowsWillBeClosed expects this query rows to be closed.
|
||||
func (e *ExpectedQuery) RowsWillBeClosed() *ExpectedQuery {
|
||||
e.rowsMustBeClosed = true
|
||||
return e
|
||||
}
|
||||
|
||||
// WillReturnError allows to set an error for expected database query
|
||||
func (e *ExpectedQuery) WillReturnError(err error) *ExpectedQuery {
|
||||
e.err = err
|
||||
return e
|
||||
}
|
||||
|
||||
// WillDelayFor allows to specify duration for which it will delay
|
||||
// result. May be used together with Context
|
||||
func (e *ExpectedQuery) WillDelayFor(duration time.Duration) *ExpectedQuery {
|
||||
e.delay = duration
|
||||
return e
|
||||
}
|
||||
|
||||
// String returns string representation
|
||||
func (e *ExpectedQuery) String() string {
|
||||
msg := "ExpectedQuery => expecting Query, QueryContext or QueryRow which:"
|
||||
msg += "\n - matches sql: '" + e.expectSQL + "'"
|
||||
|
||||
if len(e.args) == 0 {
|
||||
msg += "\n - is without arguments"
|
||||
} else {
|
||||
msg += "\n - is with arguments:\n"
|
||||
for i, arg := range e.args {
|
||||
msg += fmt.Sprintf(" %d - %+v\n", i, arg)
|
||||
}
|
||||
msg = strings.TrimSpace(msg)
|
||||
}
|
||||
|
||||
if e.rows != nil {
|
||||
msg += fmt.Sprintf("\n - %s", e.rows)
|
||||
}
|
||||
|
||||
if e.err != nil {
|
||||
msg += fmt.Sprintf("\n - should return error: %s", e.err)
|
||||
}
|
||||
|
||||
return msg
|
||||
}
|
||||
|
||||
// ExpectedExec is used to manage *sql.DB.Exec, *sql.Tx.Exec or *sql.Stmt.Exec expectations.
|
||||
// Returned by *Sqlmock.ExpectExec.
|
||||
type ExpectedExec struct {
|
||||
queryBasedExpectation
|
||||
result driver.Result
|
||||
delay time.Duration
|
||||
}
|
||||
|
||||
// WithArgs will match given expected args to actual database exec operation arguments.
|
||||
// if at least one argument does not match, it will return an error. For specific
|
||||
// arguments an sqlmock.Argument interface can be used to match an argument.
|
||||
func (e *ExpectedExec) WithArgs(args ...driver.Value) *ExpectedExec {
|
||||
e.args = args
|
||||
return e
|
||||
}
|
||||
|
||||
// WillReturnError allows to set an error for expected database exec action
|
||||
func (e *ExpectedExec) WillReturnError(err error) *ExpectedExec {
|
||||
e.err = err
|
||||
return e
|
||||
}
|
||||
|
||||
// WillDelayFor allows to specify duration for which it will delay
|
||||
// result. May be used together with Context
|
||||
func (e *ExpectedExec) WillDelayFor(duration time.Duration) *ExpectedExec {
|
||||
e.delay = duration
|
||||
return e
|
||||
}
|
||||
|
||||
// String returns string representation
|
||||
func (e *ExpectedExec) String() string {
|
||||
msg := "ExpectedExec => expecting Exec or ExecContext which:"
|
||||
msg += "\n - matches sql: '" + e.expectSQL + "'"
|
||||
|
||||
if len(e.args) == 0 {
|
||||
msg += "\n - is without arguments"
|
||||
} else {
|
||||
msg += "\n - is with arguments:\n"
|
||||
var margs []string
|
||||
for i, arg := range e.args {
|
||||
margs = append(margs, fmt.Sprintf(" %d - %+v", i, arg))
|
||||
}
|
||||
msg += strings.Join(margs, "\n")
|
||||
}
|
||||
|
||||
if e.result != nil {
|
||||
res, _ := e.result.(*result)
|
||||
msg += "\n - should return Result having:"
|
||||
msg += fmt.Sprintf("\n LastInsertId: %d", res.insertID)
|
||||
msg += fmt.Sprintf("\n RowsAffected: %d", res.rowsAffected)
|
||||
if res.err != nil {
|
||||
msg += fmt.Sprintf("\n Error: %s", res.err)
|
||||
}
|
||||
}
|
||||
|
||||
if e.err != nil {
|
||||
msg += fmt.Sprintf("\n - should return error: %s", e.err)
|
||||
}
|
||||
|
||||
return msg
|
||||
}
|
||||
|
||||
// WillReturnResult arranges for an expected Exec() to return a particular
|
||||
// result, there is sqlmock.NewResult(lastInsertID int64, affectedRows int64) method
|
||||
// to build a corresponding result. Or if actions needs to be tested against errors
|
||||
// sqlmock.NewErrorResult(err error) to return a given error.
|
||||
func (e *ExpectedExec) WillReturnResult(result driver.Result) *ExpectedExec {
|
||||
e.result = result
|
||||
return e
|
||||
}
|
||||
|
||||
// ExpectedPrepare is used to manage *sql.DB.Prepare or *sql.Tx.Prepare expectations.
|
||||
// Returned by *Sqlmock.ExpectPrepare.
|
||||
type ExpectedPrepare struct {
|
||||
commonExpectation
|
||||
mock *sqlmock
|
||||
expectSQL string
|
||||
statement driver.Stmt
|
||||
closeErr error
|
||||
mustBeClosed bool
|
||||
wasClosed bool
|
||||
delay time.Duration
|
||||
}
|
||||
|
||||
// WillReturnError allows to set an error for the expected *sql.DB.Prepare or *sql.Tx.Prepare action.
|
||||
func (e *ExpectedPrepare) WillReturnError(err error) *ExpectedPrepare {
|
||||
e.err = err
|
||||
return e
|
||||
}
|
||||
|
||||
// WillReturnCloseError allows to set an error for this prepared statement Close action
|
||||
func (e *ExpectedPrepare) WillReturnCloseError(err error) *ExpectedPrepare {
|
||||
e.closeErr = err
|
||||
return e
|
||||
}
|
||||
|
||||
// WillDelayFor allows to specify duration for which it will delay
|
||||
// result. May be used together with Context
|
||||
func (e *ExpectedPrepare) WillDelayFor(duration time.Duration) *ExpectedPrepare {
|
||||
e.delay = duration
|
||||
return e
|
||||
}
|
||||
|
||||
// WillBeClosed expects this prepared statement to
|
||||
// be closed.
|
||||
func (e *ExpectedPrepare) WillBeClosed() *ExpectedPrepare {
|
||||
e.mustBeClosed = true
|
||||
return e
|
||||
}
|
||||
|
||||
// ExpectQuery allows to expect Query() or QueryRow() on this prepared statement.
|
||||
// This method is convenient in order to prevent duplicating sql query string matching.
|
||||
func (e *ExpectedPrepare) ExpectQuery() *ExpectedQuery {
|
||||
eq := &ExpectedQuery{}
|
||||
eq.expectSQL = e.expectSQL
|
||||
eq.converter = e.mock.converter
|
||||
e.mock.expected = append(e.mock.expected, eq)
|
||||
return eq
|
||||
}
|
||||
|
||||
// ExpectExec allows to expect Exec() on this prepared statement.
|
||||
// This method is convenient in order to prevent duplicating sql query string matching.
|
||||
func (e *ExpectedPrepare) ExpectExec() *ExpectedExec {
|
||||
eq := &ExpectedExec{}
|
||||
eq.expectSQL = e.expectSQL
|
||||
eq.converter = e.mock.converter
|
||||
e.mock.expected = append(e.mock.expected, eq)
|
||||
return eq
|
||||
}
|
||||
|
||||
// String returns string representation
|
||||
func (e *ExpectedPrepare) String() string {
|
||||
msg := "ExpectedPrepare => expecting Prepare statement which:"
|
||||
msg += "\n - matches sql: '" + e.expectSQL + "'"
|
||||
|
||||
if e.err != nil {
|
||||
msg += fmt.Sprintf("\n - should return error: %s", e.err)
|
||||
}
|
||||
|
||||
if e.closeErr != nil {
|
||||
msg += fmt.Sprintf("\n - should return error on Close: %s", e.closeErr)
|
||||
}
|
||||
|
||||
return msg
|
||||
}
|
||||
|
||||
// query based expectation
|
||||
// adds a query matching logic
|
||||
type queryBasedExpectation struct {
|
||||
commonExpectation
|
||||
expectSQL string
|
||||
converter driver.ValueConverter
|
||||
args []driver.Value
|
||||
}
|
||||
|
||||
func (e *queryBasedExpectation) attemptArgMatch(args []namedValue) (err error) {
|
||||
// catch panic
|
||||
defer func() {
|
||||
if e := recover(); e != nil {
|
||||
_, ok := e.(error)
|
||||
if !ok {
|
||||
err = fmt.Errorf(e.(string))
|
||||
}
|
||||
}
|
||||
}()
|
||||
|
||||
err = e.argsMatches(args)
|
||||
return
|
||||
}
|
|
@ -1,52 +0,0 @@
|
|||
// +build !go1.8
|
||||
|
||||
package sqlmock
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// WillReturnRows specifies the set of resulting rows that will be returned
|
||||
// by the triggered query
|
||||
func (e *ExpectedQuery) WillReturnRows(rows *Rows) *ExpectedQuery {
|
||||
e.rows = &rowSets{sets: []*Rows{rows}, ex: e}
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *queryBasedExpectation) argsMatches(args []namedValue) error {
|
||||
if nil == e.args {
|
||||
return nil
|
||||
}
|
||||
if len(args) != len(e.args) {
|
||||
return fmt.Errorf("expected %d, but got %d arguments", len(e.args), len(args))
|
||||
}
|
||||
for k, v := range args {
|
||||
// custom argument matcher
|
||||
matcher, ok := e.args[k].(Argument)
|
||||
if ok {
|
||||
// @TODO: does it make sense to pass value instead of named value?
|
||||
if !matcher.Match(v.Value) {
|
||||
return fmt.Errorf("matcher %T could not match %d argument %T - %+v", matcher, k, args[k], args[k])
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
dval := e.args[k]
|
||||
// convert to driver converter
|
||||
darg, err := e.converter.ConvertValue(dval)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not convert %d argument %T - %+v to driver value: %s", k, e.args[k], e.args[k], err)
|
||||
}
|
||||
|
||||
if !driver.IsValue(darg) {
|
||||
return fmt.Errorf("argument %d: non-subset type %T returned from Value", k, darg)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(darg, v.Value) {
|
||||
return fmt.Errorf("argument %d expected [%T - %+v] does not match actual [%T - %+v]", k, darg, darg, v.Value, v.Value)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
|
@ -1,66 +0,0 @@
|
|||
// +build go1.8
|
||||
|
||||
package sqlmock
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
"reflect"
|
||||
)
|
||||
|
||||
// WillReturnRows specifies the set of resulting rows that will be returned
|
||||
// by the triggered query
|
||||
func (e *ExpectedQuery) WillReturnRows(rows ...*Rows) *ExpectedQuery {
|
||||
sets := make([]*Rows, len(rows))
|
||||
for i, r := range rows {
|
||||
sets[i] = r
|
||||
}
|
||||
e.rows = &rowSets{sets: sets, ex: e}
|
||||
return e
|
||||
}
|
||||
|
||||
func (e *queryBasedExpectation) argsMatches(args []namedValue) error {
|
||||
if nil == e.args {
|
||||
return nil
|
||||
}
|
||||
if len(args) != len(e.args) {
|
||||
return fmt.Errorf("expected %d, but got %d arguments", len(e.args), len(args))
|
||||
}
|
||||
// @TODO should we assert either all args are named or ordinal?
|
||||
for k, v := range args {
|
||||
// custom argument matcher
|
||||
matcher, ok := e.args[k].(Argument)
|
||||
if ok {
|
||||
if !matcher.Match(v.Value) {
|
||||
return fmt.Errorf("matcher %T could not match %d argument %T - %+v", matcher, k, args[k], args[k])
|
||||
}
|
||||
continue
|
||||
}
|
||||
|
||||
dval := e.args[k]
|
||||
if named, isNamed := dval.(sql.NamedArg); isNamed {
|
||||
dval = named.Value
|
||||
if v.Name != named.Name {
|
||||
return fmt.Errorf("named argument %d: name: \"%s\" does not match expected: \"%s\"", k, v.Name, named.Name)
|
||||
}
|
||||
} else if k+1 != v.Ordinal {
|
||||
return fmt.Errorf("argument %d: ordinal position: %d does not match expected: %d", k, k+1, v.Ordinal)
|
||||
}
|
||||
|
||||
// convert to driver converter
|
||||
darg, err := e.converter.ConvertValue(dval)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not convert %d argument %T - %+v to driver value: %s", k, e.args[k], e.args[k], err)
|
||||
}
|
||||
|
||||
if !driver.IsValue(darg) {
|
||||
return fmt.Errorf("argument %d: non-subset type %T returned from Value", k, darg)
|
||||
}
|
||||
|
||||
if !reflect.DeepEqual(darg, v.Value) {
|
||||
return fmt.Errorf("argument %d expected [%T - %+v] does not match actual [%T - %+v]", k, darg, darg, v.Value, v.Value)
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
|
@ -1 +0,0 @@
|
|||
module github.com/DATA-DOG/go-sqlmock
|
|
@ -1,22 +0,0 @@
|
|||
package sqlmock
|
||||
|
||||
import "database/sql/driver"
|
||||
|
||||
// ValueConverterOption allows to create a sqlmock connection
|
||||
// with a custom ValueConverter to support drivers with special data types.
|
||||
func ValueConverterOption(converter driver.ValueConverter) func(*sqlmock) error {
|
||||
return func(s *sqlmock) error {
|
||||
s.converter = converter
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
// QueryMatcherOption allows to customize SQL query matcher
|
||||
// and match SQL query strings in more sophisticated ways.
|
||||
// The default QueryMatcher is QueryMatcherRegexp.
|
||||
func QueryMatcherOption(queryMatcher QueryMatcher) func(*sqlmock) error {
|
||||
return func(s *sqlmock) error {
|
||||
s.queryMatcher = queryMatcher
|
||||
return nil
|
||||
}
|
||||
}
|
|
@ -1,68 +0,0 @@
|
|||
package sqlmock
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
"strings"
|
||||
)
|
||||
|
||||
var re = regexp.MustCompile("\\s+")
|
||||
|
||||
// strip out new lines and trim spaces
|
||||
func stripQuery(q string) (s string) {
|
||||
return strings.TrimSpace(re.ReplaceAllString(q, " "))
|
||||
}
|
||||
|
||||
// QueryMatcher is an SQL query string matcher interface,
|
||||
// which can be used to customize validation of SQL query strings.
|
||||
// As an example, external library could be used to build
|
||||
// and validate SQL ast, columns selected.
|
||||
//
|
||||
// sqlmock can be customized to implement a different QueryMatcher
|
||||
// configured through an option when sqlmock.New or sqlmock.NewWithDSN
|
||||
// is called, default QueryMatcher is QueryMatcherRegexp.
|
||||
type QueryMatcher interface {
|
||||
|
||||
// Match expected SQL query string without whitespace to
|
||||
// actual SQL.
|
||||
Match(expectedSQL, actualSQL string) error
|
||||
}
|
||||
|
||||
// QueryMatcherFunc type is an adapter to allow the use of
|
||||
// ordinary functions as QueryMatcher. If f is a function
|
||||
// with the appropriate signature, QueryMatcherFunc(f) is a
|
||||
// QueryMatcher that calls f.
|
||||
type QueryMatcherFunc func(expectedSQL, actualSQL string) error
|
||||
|
||||
// Match implements the QueryMatcher
|
||||
func (f QueryMatcherFunc) Match(expectedSQL, actualSQL string) error {
|
||||
return f(expectedSQL, actualSQL)
|
||||
}
|
||||
|
||||
// QueryMatcherRegexp is the default SQL query matcher
|
||||
// used by sqlmock. It parses expectedSQL to a regular
|
||||
// expression and attempts to match actualSQL.
|
||||
var QueryMatcherRegexp QueryMatcher = QueryMatcherFunc(func(expectedSQL, actualSQL string) error {
|
||||
expect := stripQuery(expectedSQL)
|
||||
actual := stripQuery(actualSQL)
|
||||
re, err := regexp.Compile(expect)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if !re.MatchString(actual) {
|
||||
return fmt.Errorf(`could not match actual sql: "%s" with expected regexp "%s"`, actual, re.String())
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
// QueryMatcherEqual is the SQL query matcher
|
||||
// which simply tries a case sensitive match of
|
||||
// expected and actual SQL strings without whitespace.
|
||||
var QueryMatcherEqual QueryMatcher = QueryMatcherFunc(func(expectedSQL, actualSQL string) error {
|
||||
expect := stripQuery(expectedSQL)
|
||||
actual := stripQuery(actualSQL)
|
||||
if actual != expect {
|
||||
return fmt.Errorf(`actual sql: "%s" does not equal to expected "%s"`, actual, expect)
|
||||
}
|
||||
return nil
|
||||
})
|
|
@ -1,39 +0,0 @@
|
|||
package sqlmock
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
)
|
||||
|
||||
// Result satisfies sql driver Result, which
|
||||
// holds last insert id and rows affected
|
||||
// by Exec queries
|
||||
type result struct {
|
||||
insertID int64
|
||||
rowsAffected int64
|
||||
err error
|
||||
}
|
||||
|
||||
// NewResult creates a new sql driver Result
|
||||
// for Exec based query mocks.
|
||||
func NewResult(lastInsertID int64, rowsAffected int64) driver.Result {
|
||||
return &result{
|
||||
insertID: lastInsertID,
|
||||
rowsAffected: rowsAffected,
|
||||
}
|
||||
}
|
||||
|
||||
// NewErrorResult creates a new sql driver Result
|
||||
// which returns an error given for both interface methods
|
||||
func NewErrorResult(err error) driver.Result {
|
||||
return &result{
|
||||
err: err,
|
||||
}
|
||||
}
|
||||
|
||||
func (r *result) LastInsertId() (int64, error) {
|
||||
return r.insertID, r.err
|
||||
}
|
||||
|
||||
func (r *result) RowsAffected() (int64, error) {
|
||||
return r.rowsAffected, r.err
|
||||
}
|
|
@ -1,176 +0,0 @@
|
|||
package sqlmock
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
"encoding/csv"
|
||||
"fmt"
|
||||
"io"
|
||||
"strings"
|
||||
)
|
||||
|
||||
// CSVColumnParser is a function which converts trimmed csv
|
||||
// column string to a []byte representation. Currently
|
||||
// transforms NULL to nil
|
||||
var CSVColumnParser = func(s string) []byte {
|
||||
switch {
|
||||
case strings.ToLower(s) == "null":
|
||||
return nil
|
||||
}
|
||||
return []byte(s)
|
||||
}
|
||||
|
||||
type rowSets struct {
|
||||
sets []*Rows
|
||||
pos int
|
||||
ex *ExpectedQuery
|
||||
}
|
||||
|
||||
func (rs *rowSets) Columns() []string {
|
||||
return rs.sets[rs.pos].cols
|
||||
}
|
||||
|
||||
func (rs *rowSets) Close() error {
|
||||
rs.ex.rowsWereClosed = true
|
||||
return rs.sets[rs.pos].closeErr
|
||||
}
|
||||
|
||||
// advances to next row
|
||||
func (rs *rowSets) Next(dest []driver.Value) error {
|
||||
r := rs.sets[rs.pos]
|
||||
r.pos++
|
||||
if r.pos > len(r.rows) {
|
||||
return io.EOF // per interface spec
|
||||
}
|
||||
|
||||
for i, col := range r.rows[r.pos-1] {
|
||||
dest[i] = col
|
||||
}
|
||||
|
||||
return r.nextErr[r.pos-1]
|
||||
}
|
||||
|
||||
// transforms to debuggable printable string
|
||||
func (rs *rowSets) String() string {
|
||||
if rs.empty() {
|
||||
return "with empty rows"
|
||||
}
|
||||
|
||||
msg := "should return rows:\n"
|
||||
if len(rs.sets) == 1 {
|
||||
for n, row := range rs.sets[0].rows {
|
||||
msg += fmt.Sprintf(" row %d - %+v\n", n, row)
|
||||
}
|
||||
return strings.TrimSpace(msg)
|
||||
}
|
||||
for i, set := range rs.sets {
|
||||
msg += fmt.Sprintf(" result set: %d\n", i)
|
||||
for n, row := range set.rows {
|
||||
msg += fmt.Sprintf(" row %d - %+v\n", n, row)
|
||||
}
|
||||
}
|
||||
return strings.TrimSpace(msg)
|
||||
}
|
||||
|
||||
func (rs *rowSets) empty() bool {
|
||||
for _, set := range rs.sets {
|
||||
if len(set.rows) > 0 {
|
||||
return false
|
||||
}
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
// Rows is a mocked collection of rows to
|
||||
// return for Query result
|
||||
type Rows struct {
|
||||
converter driver.ValueConverter
|
||||
cols []string
|
||||
rows [][]driver.Value
|
||||
pos int
|
||||
nextErr map[int]error
|
||||
closeErr error
|
||||
}
|
||||
|
||||
// NewRows allows Rows to be created from a
|
||||
// sql driver.Value slice or from the CSV string and
|
||||
// to be used as sql driver.Rows.
|
||||
// Use Sqlmock.NewRows instead if using a custom converter
|
||||
func NewRows(columns []string) *Rows {
|
||||
return &Rows{
|
||||
cols: columns,
|
||||
nextErr: make(map[int]error),
|
||||
converter: driver.DefaultParameterConverter,
|
||||
}
|
||||
}
|
||||
|
||||
// CloseError allows to set an error
|
||||
// which will be returned by rows.Close
|
||||
// function.
|
||||
//
|
||||
// The close error will be triggered only in cases
|
||||
// when rows.Next() EOF was not yet reached, that is
|
||||
// a default sql library behavior
|
||||
func (r *Rows) CloseError(err error) *Rows {
|
||||
r.closeErr = err
|
||||
return r
|
||||
}
|
||||
|
||||
// RowError allows to set an error
|
||||
// which will be returned when a given
|
||||
// row number is read
|
||||
func (r *Rows) RowError(row int, err error) *Rows {
|
||||
r.nextErr[row] = err
|
||||
return r
|
||||
}
|
||||
|
||||
// AddRow composed from database driver.Value slice
|
||||
// return the same instance to perform subsequent actions.
|
||||
// Note that the number of values must match the number
|
||||
// of columns
|
||||
func (r *Rows) AddRow(values ...driver.Value) *Rows {
|
||||
if len(values) != len(r.cols) {
|
||||
panic("Expected number of values to match number of columns")
|
||||
}
|
||||
|
||||
row := make([]driver.Value, len(r.cols))
|
||||
for i, v := range values {
|
||||
// Convert user-friendly values (such as int or driver.Valuer)
|
||||
// to database/sql native value (driver.Value such as int64)
|
||||
var err error
|
||||
v, err = r.converter.ConvertValue(v)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf(
|
||||
"row #%d, column #%d (%q) type %T: %s",
|
||||
len(r.rows)+1, i, r.cols[i], values[i], err,
|
||||
))
|
||||
}
|
||||
|
||||
row[i] = v
|
||||
}
|
||||
|
||||
r.rows = append(r.rows, row)
|
||||
return r
|
||||
}
|
||||
|
||||
// FromCSVString build rows from csv string.
|
||||
// return the same instance to perform subsequent actions.
|
||||
// Note that the number of values must match the number
|
||||
// of columns
|
||||
func (r *Rows) FromCSVString(s string) *Rows {
|
||||
res := strings.NewReader(strings.TrimSpace(s))
|
||||
csvReader := csv.NewReader(res)
|
||||
|
||||
for {
|
||||
res, err := csvReader.Read()
|
||||
if err != nil || res == nil {
|
||||
break
|
||||
}
|
||||
|
||||
row := make([]driver.Value, len(r.cols))
|
||||
for i, v := range res {
|
||||
row[i] = CSVColumnParser(strings.TrimSpace(v))
|
||||
}
|
||||
r.rows = append(r.rows, row)
|
||||
}
|
||||
return r
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
// +build go1.8
|
||||
|
||||
package sqlmock
|
||||
|
||||
import "io"
|
||||
|
||||
// Implement the "RowsNextResultSet" interface
|
||||
func (rs *rowSets) HasNextResultSet() bool {
|
||||
return rs.pos+1 < len(rs.sets)
|
||||
}
|
||||
|
||||
// Implement the "RowsNextResultSet" interface
|
||||
func (rs *rowSets) NextResultSet() error {
|
||||
if !rs.HasNextResultSet() {
|
||||
return io.EOF
|
||||
}
|
||||
|
||||
rs.pos++
|
||||
return nil
|
||||
}
|
|
@ -1,589 +0,0 @@
|
|||
/*
|
||||
Package sqlmock is a mock library implementing sql driver. Which has one and only
|
||||
purpose - to simulate any sql driver behavior in tests, without needing a real
|
||||
database connection. It helps to maintain correct **TDD** workflow.
|
||||
|
||||
It does not require any modifications to your source code in order to test
|
||||
and mock database operations. Supports concurrency and multiple database mocking.
|
||||
|
||||
The driver allows to mock any sql driver method behavior.
|
||||
*/
|
||||
package sqlmock
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
"time"
|
||||
)
|
||||
|
||||
// Sqlmock interface serves to create expectations
|
||||
// for any kind of database action in order to mock
|
||||
// and test real database behavior.
|
||||
type Sqlmock interface {
|
||||
|
||||
// ExpectClose queues an expectation for this database
|
||||
// action to be triggered. the *ExpectedClose allows
|
||||
// to mock database response
|
||||
ExpectClose() *ExpectedClose
|
||||
|
||||
// ExpectationsWereMet checks whether all queued expectations
|
||||
// were met in order. If any of them was not met - an error is returned.
|
||||
ExpectationsWereMet() error
|
||||
|
||||
// ExpectPrepare expects Prepare() to be called with expectedSQL query.
|
||||
// the *ExpectedPrepare allows to mock database response.
|
||||
// Note that you may expect Query() or Exec() on the *ExpectedPrepare
|
||||
// statement to prevent repeating expectedSQL
|
||||
ExpectPrepare(expectedSQL string) *ExpectedPrepare
|
||||
|
||||
// ExpectQuery expects Query() or QueryRow() to be called with expectedSQL query.
|
||||
// the *ExpectedQuery allows to mock database response.
|
||||
ExpectQuery(expectedSQL string) *ExpectedQuery
|
||||
|
||||
// ExpectExec expects Exec() to be called with expectedSQL query.
|
||||
// the *ExpectedExec allows to mock database response
|
||||
ExpectExec(expectedSQL string) *ExpectedExec
|
||||
|
||||
// ExpectBegin expects *sql.DB.Begin to be called.
|
||||
// the *ExpectedBegin allows to mock database response
|
||||
ExpectBegin() *ExpectedBegin
|
||||
|
||||
// ExpectCommit expects *sql.Tx.Commit to be called.
|
||||
// the *ExpectedCommit allows to mock database response
|
||||
ExpectCommit() *ExpectedCommit
|
||||
|
||||
// ExpectRollback expects *sql.Tx.Rollback to be called.
|
||||
// the *ExpectedRollback allows to mock database response
|
||||
ExpectRollback() *ExpectedRollback
|
||||
|
||||
// MatchExpectationsInOrder gives an option whether to match all
|
||||
// expectations in the order they were set or not.
|
||||
//
|
||||
// By default it is set to - true. But if you use goroutines
|
||||
// to parallelize your query executation, that option may
|
||||
// be handy.
|
||||
//
|
||||
// This option may be turned on anytime during tests. As soon
|
||||
// as it is switched to false, expectations will be matched
|
||||
// in any order. Or otherwise if switched to true, any unmatched
|
||||
// expectations will be expected in order
|
||||
MatchExpectationsInOrder(bool)
|
||||
|
||||
// NewRows allows Rows to be created from a
|
||||
// sql driver.Value slice or from the CSV string and
|
||||
// to be used as sql driver.Rows.
|
||||
NewRows(columns []string) *Rows
|
||||
}
|
||||
|
||||
type sqlmock struct {
|
||||
ordered bool
|
||||
dsn string
|
||||
opened int
|
||||
drv *mockDriver
|
||||
converter driver.ValueConverter
|
||||
queryMatcher QueryMatcher
|
||||
|
||||
expected []expectation
|
||||
}
|
||||
|
||||
func (c *sqlmock) open(options []func(*sqlmock) error) (*sql.DB, Sqlmock, error) {
|
||||
db, err := sql.Open("sqlmock", c.dsn)
|
||||
if err != nil {
|
||||
return db, c, err
|
||||
}
|
||||
for _, option := range options {
|
||||
err := option(c)
|
||||
if err != nil {
|
||||
return db, c, err
|
||||
}
|
||||
}
|
||||
if c.converter == nil {
|
||||
c.converter = driver.DefaultParameterConverter
|
||||
}
|
||||
if c.queryMatcher == nil {
|
||||
c.queryMatcher = QueryMatcherRegexp
|
||||
}
|
||||
return db, c, db.Ping()
|
||||
}
|
||||
|
||||
func (c *sqlmock) ExpectClose() *ExpectedClose {
|
||||
e := &ExpectedClose{}
|
||||
c.expected = append(c.expected, e)
|
||||
return e
|
||||
}
|
||||
|
||||
func (c *sqlmock) MatchExpectationsInOrder(b bool) {
|
||||
c.ordered = b
|
||||
}
|
||||
|
||||
// Close a mock database driver connection. It may or may not
|
||||
// be called depending on the circumstances, but if it is called
|
||||
// there must be an *ExpectedClose expectation satisfied.
|
||||
// meets http://golang.org/pkg/database/sql/driver/#Conn interface
|
||||
func (c *sqlmock) Close() error {
|
||||
c.drv.Lock()
|
||||
defer c.drv.Unlock()
|
||||
|
||||
c.opened--
|
||||
if c.opened == 0 {
|
||||
delete(c.drv.conns, c.dsn)
|
||||
}
|
||||
|
||||
var expected *ExpectedClose
|
||||
var fulfilled int
|
||||
var ok bool
|
||||
for _, next := range c.expected {
|
||||
next.Lock()
|
||||
if next.fulfilled() {
|
||||
next.Unlock()
|
||||
fulfilled++
|
||||
continue
|
||||
}
|
||||
|
||||
if expected, ok = next.(*ExpectedClose); ok {
|
||||
break
|
||||
}
|
||||
|
||||
next.Unlock()
|
||||
if c.ordered {
|
||||
return fmt.Errorf("call to database Close, was not expected, next expectation is: %s", next)
|
||||
}
|
||||
}
|
||||
|
||||
if expected == nil {
|
||||
msg := "call to database Close was not expected"
|
||||
if fulfilled == len(c.expected) {
|
||||
msg = "all expectations were already fulfilled, " + msg
|
||||
}
|
||||
return fmt.Errorf(msg)
|
||||
}
|
||||
|
||||
expected.triggered = true
|
||||
expected.Unlock()
|
||||
return expected.err
|
||||
}
|
||||
|
||||
func (c *sqlmock) ExpectationsWereMet() error {
|
||||
for _, e := range c.expected {
|
||||
e.Lock()
|
||||
fulfilled := e.fulfilled()
|
||||
e.Unlock()
|
||||
|
||||
if !fulfilled {
|
||||
return fmt.Errorf("there is a remaining expectation which was not matched: %s", e)
|
||||
}
|
||||
|
||||
// for expected prepared statement check whether it was closed if expected
|
||||
if prep, ok := e.(*ExpectedPrepare); ok {
|
||||
if prep.mustBeClosed && !prep.wasClosed {
|
||||
return fmt.Errorf("expected prepared statement to be closed, but it was not: %s", prep)
|
||||
}
|
||||
}
|
||||
|
||||
// must check whether all expected queried rows are closed
|
||||
if query, ok := e.(*ExpectedQuery); ok {
|
||||
if query.rowsMustBeClosed && !query.rowsWereClosed {
|
||||
return fmt.Errorf("expected query rows to be closed, but it was not: %s", query)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Begin meets http://golang.org/pkg/database/sql/driver/#Conn interface
|
||||
func (c *sqlmock) Begin() (driver.Tx, error) {
|
||||
ex, err := c.begin()
|
||||
if ex != nil {
|
||||
time.Sleep(ex.delay)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return c, nil
|
||||
}
|
||||
|
||||
func (c *sqlmock) begin() (*ExpectedBegin, error) {
|
||||
var expected *ExpectedBegin
|
||||
var ok bool
|
||||
var fulfilled int
|
||||
for _, next := range c.expected {
|
||||
next.Lock()
|
||||
if next.fulfilled() {
|
||||
next.Unlock()
|
||||
fulfilled++
|
||||
continue
|
||||
}
|
||||
|
||||
if expected, ok = next.(*ExpectedBegin); ok {
|
||||
break
|
||||
}
|
||||
|
||||
next.Unlock()
|
||||
if c.ordered {
|
||||
return nil, fmt.Errorf("call to database transaction Begin, was not expected, next expectation is: %s", next)
|
||||
}
|
||||
}
|
||||
if expected == nil {
|
||||
msg := "call to database transaction Begin was not expected"
|
||||
if fulfilled == len(c.expected) {
|
||||
msg = "all expectations were already fulfilled, " + msg
|
||||
}
|
||||
return nil, fmt.Errorf(msg)
|
||||
}
|
||||
|
||||
expected.triggered = true
|
||||
expected.Unlock()
|
||||
|
||||
return expected, expected.err
|
||||
}
|
||||
|
||||
func (c *sqlmock) ExpectBegin() *ExpectedBegin {
|
||||
e := &ExpectedBegin{}
|
||||
c.expected = append(c.expected, e)
|
||||
return e
|
||||
}
|
||||
|
||||
// Exec meets http://golang.org/pkg/database/sql/driver/#Execer
|
||||
func (c *sqlmock) Exec(query string, args []driver.Value) (driver.Result, error) {
|
||||
namedArgs := make([]namedValue, len(args))
|
||||
for i, v := range args {
|
||||
namedArgs[i] = namedValue{
|
||||
Ordinal: i + 1,
|
||||
Value: v,
|
||||
}
|
||||
}
|
||||
|
||||
ex, err := c.exec(query, namedArgs)
|
||||
if ex != nil {
|
||||
time.Sleep(ex.delay)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ex.result, nil
|
||||
}
|
||||
|
||||
func (c *sqlmock) exec(query string, args []namedValue) (*ExpectedExec, error) {
|
||||
var expected *ExpectedExec
|
||||
var fulfilled int
|
||||
var ok bool
|
||||
for _, next := range c.expected {
|
||||
next.Lock()
|
||||
if next.fulfilled() {
|
||||
next.Unlock()
|
||||
fulfilled++
|
||||
continue
|
||||
}
|
||||
|
||||
if c.ordered {
|
||||
if expected, ok = next.(*ExpectedExec); ok {
|
||||
break
|
||||
}
|
||||
next.Unlock()
|
||||
return nil, fmt.Errorf("call to ExecQuery '%s' with args %+v, was not expected, next expectation is: %s", query, args, next)
|
||||
}
|
||||
if exec, ok := next.(*ExpectedExec); ok {
|
||||
if err := c.queryMatcher.Match(exec.expectSQL, query); err != nil {
|
||||
next.Unlock()
|
||||
continue
|
||||
}
|
||||
|
||||
if err := exec.attemptArgMatch(args); err == nil {
|
||||
expected = exec
|
||||
break
|
||||
}
|
||||
}
|
||||
next.Unlock()
|
||||
}
|
||||
if expected == nil {
|
||||
msg := "call to ExecQuery '%s' with args %+v was not expected"
|
||||
if fulfilled == len(c.expected) {
|
||||
msg = "all expectations were already fulfilled, " + msg
|
||||
}
|
||||
return nil, fmt.Errorf(msg, query, args)
|
||||
}
|
||||
defer expected.Unlock()
|
||||
|
||||
if err := c.queryMatcher.Match(expected.expectSQL, query); err != nil {
|
||||
return nil, fmt.Errorf("ExecQuery: %v", err)
|
||||
}
|
||||
|
||||
if err := expected.argsMatches(args); err != nil {
|
||||
return nil, fmt.Errorf("ExecQuery '%s', arguments do not match: %s", query, err)
|
||||
}
|
||||
|
||||
expected.triggered = true
|
||||
if expected.err != nil {
|
||||
return expected, expected.err // mocked to return error
|
||||
}
|
||||
|
||||
if expected.result == nil {
|
||||
return nil, fmt.Errorf("ExecQuery '%s' with args %+v, must return a database/sql/driver.Result, but it was not set for expectation %T as %+v", query, args, expected, expected)
|
||||
}
|
||||
|
||||
return expected, nil
|
||||
}
|
||||
|
||||
func (c *sqlmock) ExpectExec(expectedSQL string) *ExpectedExec {
|
||||
e := &ExpectedExec{}
|
||||
e.expectSQL = expectedSQL
|
||||
e.converter = c.converter
|
||||
c.expected = append(c.expected, e)
|
||||
return e
|
||||
}
|
||||
|
||||
// Prepare meets http://golang.org/pkg/database/sql/driver/#Conn interface
|
||||
func (c *sqlmock) Prepare(query string) (driver.Stmt, error) {
|
||||
ex, err := c.prepare(query)
|
||||
if ex != nil {
|
||||
time.Sleep(ex.delay)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return &statement{c, ex, query}, nil
|
||||
}
|
||||
|
||||
func (c *sqlmock) prepare(query string) (*ExpectedPrepare, error) {
|
||||
var expected *ExpectedPrepare
|
||||
var fulfilled int
|
||||
var ok bool
|
||||
|
||||
for _, next := range c.expected {
|
||||
next.Lock()
|
||||
if next.fulfilled() {
|
||||
next.Unlock()
|
||||
fulfilled++
|
||||
continue
|
||||
}
|
||||
|
||||
if c.ordered {
|
||||
if expected, ok = next.(*ExpectedPrepare); ok {
|
||||
break
|
||||
}
|
||||
|
||||
next.Unlock()
|
||||
return nil, fmt.Errorf("call to Prepare statement with query '%s', was not expected, next expectation is: %s", query, next)
|
||||
}
|
||||
|
||||
if pr, ok := next.(*ExpectedPrepare); ok {
|
||||
if err := c.queryMatcher.Match(pr.expectSQL, query); err == nil {
|
||||
expected = pr
|
||||
break
|
||||
}
|
||||
}
|
||||
next.Unlock()
|
||||
}
|
||||
|
||||
if expected == nil {
|
||||
msg := "call to Prepare '%s' query was not expected"
|
||||
if fulfilled == len(c.expected) {
|
||||
msg = "all expectations were already fulfilled, " + msg
|
||||
}
|
||||
return nil, fmt.Errorf(msg, query)
|
||||
}
|
||||
defer expected.Unlock()
|
||||
if err := c.queryMatcher.Match(expected.expectSQL, query); err != nil {
|
||||
return nil, fmt.Errorf("Prepare: %v", err)
|
||||
}
|
||||
|
||||
expected.triggered = true
|
||||
return expected, expected.err
|
||||
}
|
||||
|
||||
func (c *sqlmock) ExpectPrepare(expectedSQL string) *ExpectedPrepare {
|
||||
e := &ExpectedPrepare{expectSQL: expectedSQL, mock: c}
|
||||
c.expected = append(c.expected, e)
|
||||
return e
|
||||
}
|
||||
|
||||
type namedValue struct {
|
||||
Name string
|
||||
Ordinal int
|
||||
Value driver.Value
|
||||
}
|
||||
|
||||
// Query meets http://golang.org/pkg/database/sql/driver/#Queryer
|
||||
func (c *sqlmock) Query(query string, args []driver.Value) (driver.Rows, error) {
|
||||
namedArgs := make([]namedValue, len(args))
|
||||
for i, v := range args {
|
||||
namedArgs[i] = namedValue{
|
||||
Ordinal: i + 1,
|
||||
Value: v,
|
||||
}
|
||||
}
|
||||
|
||||
ex, err := c.query(query, namedArgs)
|
||||
if ex != nil {
|
||||
time.Sleep(ex.delay)
|
||||
}
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return ex.rows, nil
|
||||
}
|
||||
|
||||
func (c *sqlmock) query(query string, args []namedValue) (*ExpectedQuery, error) {
|
||||
var expected *ExpectedQuery
|
||||
var fulfilled int
|
||||
var ok bool
|
||||
for _, next := range c.expected {
|
||||
next.Lock()
|
||||
if next.fulfilled() {
|
||||
next.Unlock()
|
||||
fulfilled++
|
||||
continue
|
||||
}
|
||||
|
||||
if c.ordered {
|
||||
if expected, ok = next.(*ExpectedQuery); ok {
|
||||
break
|
||||
}
|
||||
next.Unlock()
|
||||
return nil, fmt.Errorf("call to Query '%s' with args %+v, was not expected, next expectation is: %s", query, args, next)
|
||||
}
|
||||
if qr, ok := next.(*ExpectedQuery); ok {
|
||||
if err := c.queryMatcher.Match(qr.expectSQL, query); err != nil {
|
||||
next.Unlock()
|
||||
continue
|
||||
}
|
||||
if err := qr.attemptArgMatch(args); err == nil {
|
||||
expected = qr
|
||||
break
|
||||
}
|
||||
}
|
||||
next.Unlock()
|
||||
}
|
||||
|
||||
if expected == nil {
|
||||
msg := "call to Query '%s' with args %+v was not expected"
|
||||
if fulfilled == len(c.expected) {
|
||||
msg = "all expectations were already fulfilled, " + msg
|
||||
}
|
||||
return nil, fmt.Errorf(msg, query, args)
|
||||
}
|
||||
|
||||
defer expected.Unlock()
|
||||
|
||||
if err := c.queryMatcher.Match(expected.expectSQL, query); err != nil {
|
||||
return nil, fmt.Errorf("Query: %v", err)
|
||||
}
|
||||
|
||||
if err := expected.argsMatches(args); err != nil {
|
||||
return nil, fmt.Errorf("Query '%s', arguments do not match: %s", query, err)
|
||||
}
|
||||
|
||||
expected.triggered = true
|
||||
if expected.err != nil {
|
||||
return expected, expected.err // mocked to return error
|
||||
}
|
||||
|
||||
if expected.rows == nil {
|
||||
return nil, fmt.Errorf("Query '%s' with args %+v, must return a database/sql/driver.Rows, but it was not set for expectation %T as %+v", query, args, expected, expected)
|
||||
}
|
||||
return expected, nil
|
||||
}
|
||||
|
||||
func (c *sqlmock) ExpectQuery(expectedSQL string) *ExpectedQuery {
|
||||
e := &ExpectedQuery{}
|
||||
e.expectSQL = expectedSQL
|
||||
e.converter = c.converter
|
||||
c.expected = append(c.expected, e)
|
||||
return e
|
||||
}
|
||||
|
||||
func (c *sqlmock) ExpectCommit() *ExpectedCommit {
|
||||
e := &ExpectedCommit{}
|
||||
c.expected = append(c.expected, e)
|
||||
return e
|
||||
}
|
||||
|
||||
func (c *sqlmock) ExpectRollback() *ExpectedRollback {
|
||||
e := &ExpectedRollback{}
|
||||
c.expected = append(c.expected, e)
|
||||
return e
|
||||
}
|
||||
|
||||
// Commit meets http://golang.org/pkg/database/sql/driver/#Tx
|
||||
func (c *sqlmock) Commit() error {
|
||||
var expected *ExpectedCommit
|
||||
var fulfilled int
|
||||
var ok bool
|
||||
for _, next := range c.expected {
|
||||
next.Lock()
|
||||
if next.fulfilled() {
|
||||
next.Unlock()
|
||||
fulfilled++
|
||||
continue
|
||||
}
|
||||
|
||||
if expected, ok = next.(*ExpectedCommit); ok {
|
||||
break
|
||||
}
|
||||
|
||||
next.Unlock()
|
||||
if c.ordered {
|
||||
return fmt.Errorf("call to Commit transaction, was not expected, next expectation is: %s", next)
|
||||
}
|
||||
}
|
||||
if expected == nil {
|
||||
msg := "call to Commit transaction was not expected"
|
||||
if fulfilled == len(c.expected) {
|
||||
msg = "all expectations were already fulfilled, " + msg
|
||||
}
|
||||
return fmt.Errorf(msg)
|
||||
}
|
||||
|
||||
expected.triggered = true
|
||||
expected.Unlock()
|
||||
return expected.err
|
||||
}
|
||||
|
||||
// Rollback meets http://golang.org/pkg/database/sql/driver/#Tx
|
||||
func (c *sqlmock) Rollback() error {
|
||||
var expected *ExpectedRollback
|
||||
var fulfilled int
|
||||
var ok bool
|
||||
for _, next := range c.expected {
|
||||
next.Lock()
|
||||
if next.fulfilled() {
|
||||
next.Unlock()
|
||||
fulfilled++
|
||||
continue
|
||||
}
|
||||
|
||||
if expected, ok = next.(*ExpectedRollback); ok {
|
||||
break
|
||||
}
|
||||
|
||||
next.Unlock()
|
||||
if c.ordered {
|
||||
return fmt.Errorf("call to Rollback transaction, was not expected, next expectation is: %s", next)
|
||||
}
|
||||
}
|
||||
if expected == nil {
|
||||
msg := "call to Rollback transaction was not expected"
|
||||
if fulfilled == len(c.expected) {
|
||||
msg = "all expectations were already fulfilled, " + msg
|
||||
}
|
||||
return fmt.Errorf(msg)
|
||||
}
|
||||
|
||||
expected.triggered = true
|
||||
expected.Unlock()
|
||||
return expected.err
|
||||
}
|
||||
|
||||
// NewRows allows Rows to be created from a
|
||||
// sql driver.Value slice or from the CSV string and
|
||||
// to be used as sql driver.Rows.
|
||||
func (c *sqlmock) NewRows(columns []string) *Rows {
|
||||
r := NewRows(columns)
|
||||
r.converter = c.converter
|
||||
return r
|
||||
}
|
|
@ -1,121 +0,0 @@
|
|||
// +build go1.8
|
||||
|
||||
package sqlmock
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql/driver"
|
||||
"errors"
|
||||
"time"
|
||||
)
|
||||
|
||||
// ErrCancelled defines an error value, which can be expected in case of
|
||||
// such cancellation error.
|
||||
var ErrCancelled = errors.New("canceling query due to user request")
|
||||
|
||||
// Implement the "QueryerContext" interface
|
||||
func (c *sqlmock) QueryContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Rows, error) {
|
||||
namedArgs := make([]namedValue, len(args))
|
||||
for i, nv := range args {
|
||||
namedArgs[i] = namedValue(nv)
|
||||
}
|
||||
|
||||
ex, err := c.query(query, namedArgs)
|
||||
if ex != nil {
|
||||
select {
|
||||
case <-time.After(ex.delay):
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ex.rows, nil
|
||||
case <-ctx.Done():
|
||||
return nil, ErrCancelled
|
||||
}
|
||||
}
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Implement the "ExecerContext" interface
|
||||
func (c *sqlmock) ExecContext(ctx context.Context, query string, args []driver.NamedValue) (driver.Result, error) {
|
||||
namedArgs := make([]namedValue, len(args))
|
||||
for i, nv := range args {
|
||||
namedArgs[i] = namedValue(nv)
|
||||
}
|
||||
|
||||
ex, err := c.exec(query, namedArgs)
|
||||
if ex != nil {
|
||||
select {
|
||||
case <-time.After(ex.delay):
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return ex.result, nil
|
||||
case <-ctx.Done():
|
||||
return nil, ErrCancelled
|
||||
}
|
||||
}
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Implement the "ConnBeginTx" interface
|
||||
func (c *sqlmock) BeginTx(ctx context.Context, opts driver.TxOptions) (driver.Tx, error) {
|
||||
ex, err := c.begin()
|
||||
if ex != nil {
|
||||
select {
|
||||
case <-time.After(ex.delay):
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return c, nil
|
||||
case <-ctx.Done():
|
||||
return nil, ErrCancelled
|
||||
}
|
||||
}
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Implement the "ConnPrepareContext" interface
|
||||
func (c *sqlmock) PrepareContext(ctx context.Context, query string) (driver.Stmt, error) {
|
||||
ex, err := c.prepare(query)
|
||||
if ex != nil {
|
||||
select {
|
||||
case <-time.After(ex.delay):
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return &statement{c, ex, query}, nil
|
||||
case <-ctx.Done():
|
||||
return nil, ErrCancelled
|
||||
}
|
||||
}
|
||||
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// Implement the "Pinger" interface
|
||||
// for now we do not have a Ping expectation
|
||||
// may be something for the future
|
||||
func (c *sqlmock) Ping(ctx context.Context) error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Implement the "StmtExecContext" interface
|
||||
func (stmt *statement) ExecContext(ctx context.Context, args []driver.NamedValue) (driver.Result, error) {
|
||||
return stmt.conn.ExecContext(ctx, stmt.query, args)
|
||||
}
|
||||
|
||||
// Implement the "StmtQueryContext" interface
|
||||
func (stmt *statement) QueryContext(ctx context.Context, args []driver.NamedValue) (driver.Rows, error) {
|
||||
return stmt.conn.QueryContext(ctx, stmt.query, args)
|
||||
}
|
||||
|
||||
// @TODO maybe add ExpectedBegin.WithOptions(driver.TxOptions)
|
||||
|
||||
// CheckNamedValue meets https://golang.org/pkg/database/sql/driver/#NamedValueChecker
|
||||
func (c *sqlmock) CheckNamedValue(nv *driver.NamedValue) (err error) {
|
||||
nv.Value, err = c.converter.ConvertValue(nv.Value)
|
||||
return err
|
||||
}
|
|
@ -1,28 +0,0 @@
|
|||
package sqlmock
|
||||
|
||||
import (
|
||||
"database/sql/driver"
|
||||
)
|
||||
|
||||
type statement struct {
|
||||
conn *sqlmock
|
||||
ex *ExpectedPrepare
|
||||
query string
|
||||
}
|
||||
|
||||
func (stmt *statement) Close() error {
|
||||
stmt.ex.wasClosed = true
|
||||
return stmt.ex.closeErr
|
||||
}
|
||||
|
||||
func (stmt *statement) NumInput() int {
|
||||
return -1
|
||||
}
|
||||
|
||||
func (stmt *statement) Exec(args []driver.Value) (driver.Result, error) {
|
||||
return stmt.conn.Exec(stmt.query, args)
|
||||
}
|
||||
|
||||
func (stmt *statement) Query(args []driver.Value) (driver.Rows, error) {
|
||||
return stmt.conn.Query(stmt.query, args)
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
Copyright (c) 2013 CloudFlare, Inc.
|
||||
All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without modification,
|
||||
are permitted provided that the following conditions are met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
list of conditions and the following disclaimer.
|
||||
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
list of conditions and the following disclaimer in the documentation and/or
|
||||
other materials provided with the distribution.
|
||||
|
||||
* Neither the name of the CloudFlare, Inc. nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
||||
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
|
||||
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
|
||||
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
|
||||
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
|
||||
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
|
||||
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@ -1,14 +0,0 @@
|
|||
GCFLAGS :=
|
||||
LDFLAGS :=
|
||||
|
||||
.PHONY: install
|
||||
install:
|
||||
@go install -v .
|
||||
|
||||
.PHONY: test
|
||||
test:
|
||||
@go test -gcflags='$(GCFLAGS)' -ldflags='$(LDFLAGS)' .
|
||||
|
||||
.PHONY: bench
|
||||
bench:
|
||||
@go test -gcflags='$(GCFLAGS)' -ldflags='$(LDFLAGS)' -bench .
|
|
@ -1,4 +0,0 @@
|
|||
golz4
|
||||
=====
|
||||
|
||||
Golang interface to LZ4 compression
|
|
@ -1,4 +0,0 @@
|
|||
// Package lz4 implements compression using lz4.c and lz4hc.c
|
||||
//
|
||||
// Copyright (c) 2013 CloudFlare, Inc.
|
||||
package lz4
|
|
@ -1,55 +0,0 @@
|
|||
package lz4
|
||||
|
||||
// #cgo CFLAGS: -O3
|
||||
// #include "src/lz4.h"
|
||||
// #include "src/lz4.c"
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"unsafe"
|
||||
)
|
||||
|
||||
// p gets a char pointer to the first byte of a []byte slice
|
||||
func p(in []byte) *C.char {
|
||||
if len(in) == 0 {
|
||||
return (*C.char)(unsafe.Pointer(nil))
|
||||
}
|
||||
return (*C.char)(unsafe.Pointer(&in[0]))
|
||||
}
|
||||
|
||||
// clen gets the length of a []byte slice as a char *
|
||||
func clen(s []byte) C.int {
|
||||
return C.int(len(s))
|
||||
}
|
||||
|
||||
// Uncompress with a known output size. len(out) should be equal to
|
||||
// the length of the uncompressed out.
|
||||
func Uncompress(in, out []byte) (error) {
|
||||
if int(C.LZ4_decompress_safe(p(in), p(out), clen(in), clen(out))) < 0 {
|
||||
return errors.New("Malformed compression stream")
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
// CompressBound calculates the size of the output buffer needed by
|
||||
// Compress. This is based on the following macro:
|
||||
//
|
||||
// #define LZ4_COMPRESSBOUND(isize)
|
||||
// ((unsigned int)(isize) > (unsigned int)LZ4_MAX_INPUT_SIZE ? 0 : (isize) + ((isize)/255) + 16)
|
||||
func CompressBound(in []byte) int {
|
||||
return len(in) + ((len(in) / 255) + 16)
|
||||
}
|
||||
|
||||
// Compress compresses in and puts the content in out. len(out)
|
||||
// should have enough space for the compressed data (use CompressBound
|
||||
// to calculate). Returns the number of bytes in the out slice.
|
||||
func Compress(in, out []byte) (outSize int, err error) {
|
||||
outSize = int(C.LZ4_compress_limitedOutput(p(in), p(out), clen(in), clen(out)))
|
||||
if outSize == 0 {
|
||||
err = fmt.Errorf("insufficient space for compression")
|
||||
}
|
||||
return
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
package lz4
|
||||
|
||||
// #cgo CFLAGS: -O3
|
||||
// #include "src/lz4hc.h"
|
||||
// #include "src/lz4hc.c"
|
||||
import "C"
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// CompressHC compresses in and puts the content in out. len(out)
|
||||
// should have enough space for the compressed data (use CompressBound
|
||||
// to calculate). Returns the number of bytes in the out slice. Determines
|
||||
// the compression level automatically.
|
||||
func CompressHC(in, out []byte) (int, error) {
|
||||
// 0 automatically sets the compression level.
|
||||
return CompressHCLevel(in, out, 0)
|
||||
}
|
||||
|
||||
// CompressHCLevel compresses in at the given compression level and puts the
|
||||
// content in out. len(out) should have enough space for the compressed data
|
||||
// (use CompressBound to calculate). Returns the number of bytes in the out
|
||||
// slice. To automatically choose the compression level, use 0. Otherwise, use
|
||||
// any value in the inclusive range 1 (worst) through 16 (best). Most
|
||||
// applications will prefer CompressHC.
|
||||
func CompressHCLevel(in, out []byte, level int) (outSize int, err error) {
|
||||
// LZ4HC does not handle empty buffers. Pass through to Compress.
|
||||
if len(in) == 0 || len(out) == 0 {
|
||||
return Compress(in, out)
|
||||
}
|
||||
|
||||
outSize = int(C.LZ4_compressHC2_limitedOutput(p(in), p(out), clen(in), clen(out), C.int(level)))
|
||||
if outSize == 0 {
|
||||
err = fmt.Errorf("insufficient space for compression")
|
||||
}
|
||||
return
|
||||
}
|
|
@ -1,143 +0,0 @@
|
|||
CANTO I
|
||||
|
||||
|
||||
IN the midway of this our mortal life,
|
||||
I found me in a gloomy wood, astray
|
||||
Gone from the path direct: and e'en to tell
|
||||
It were no easy task, how savage wild
|
||||
That forest, how robust and rough its growth,
|
||||
Which to remember only, my dismay
|
||||
Renews, in bitterness not far from death.
|
||||
Yet to discourse of what there good befell,
|
||||
All else will I relate discover'd there.
|
||||
How first I enter'd it I scarce can say,
|
||||
Such sleepy dullness in that instant weigh'd
|
||||
My senses down, when the true path I left,
|
||||
But when a mountain's foot I reach'd, where clos'd
|
||||
The valley, that had pierc'd my heart with dread,
|
||||
I look'd aloft, and saw his shoulders broad
|
||||
Already vested with that planet's beam,
|
||||
Who leads all wanderers safe through every way.
|
||||
|
||||
Then was a little respite to the fear,
|
||||
That in my heart's recesses deep had lain,
|
||||
All of that night, so pitifully pass'd:
|
||||
And as a man, with difficult short breath,
|
||||
Forespent with toiling, 'scap'd from sea to shore,
|
||||
Turns to the perilous wide waste, and stands
|
||||
At gaze; e'en so my spirit, that yet fail'd
|
||||
Struggling with terror, turn'd to view the straits,
|
||||
That none hath pass'd and liv'd. My weary frame
|
||||
After short pause recomforted, again
|
||||
I journey'd on over that lonely steep,
|
||||
|
||||
The hinder foot still firmer. Scarce the ascent
|
||||
Began, when, lo! a panther, nimble, light,
|
||||
And cover'd with a speckled skin, appear'd,
|
||||
Nor, when it saw me, vanish'd, rather strove
|
||||
To check my onward going; that ofttimes
|
||||
With purpose to retrace my steps I turn'd.
|
||||
|
||||
The hour was morning's prime, and on his way
|
||||
Aloft the sun ascended with those stars,
|
||||
That with him rose, when Love divine first mov'd
|
||||
Those its fair works: so that with joyous hope
|
||||
All things conspir'd to fill me, the gay skin
|
||||
Of that swift animal, the matin dawn
|
||||
And the sweet season. Soon that joy was chas'd,
|
||||
And by new dread succeeded, when in view
|
||||
A lion came, 'gainst me, as it appear'd,
|
||||
|
||||
With his head held aloft and hunger-mad,
|
||||
That e'en the air was fear-struck. A she-wolf
|
||||
Was at his heels, who in her leanness seem'd
|
||||
Full of all wants, and many a land hath made
|
||||
Disconsolate ere now. She with such fear
|
||||
O'erwhelmed me, at the sight of her appall'd,
|
||||
That of the height all hope I lost. As one,
|
||||
Who with his gain elated, sees the time
|
||||
When all unwares is gone, he inwardly
|
||||
Mourns with heart-griping anguish; such was I,
|
||||
Haunted by that fell beast, never at peace,
|
||||
Who coming o'er against me, by degrees
|
||||
Impell'd me where the sun in silence rests.
|
||||
|
||||
While to the lower space with backward step
|
||||
I fell, my ken discern'd the form one of one,
|
||||
Whose voice seem'd faint through long disuse of speech.
|
||||
When him in that great desert I espied,
|
||||
"Have mercy on me!" cried I out aloud,
|
||||
"Spirit! or living man! what e'er thou be!"
|
||||
|
||||
He answer'd: "Now not man, man once I was,
|
||||
And born of Lombard parents, Mantuana both
|
||||
By country, when the power of Julius yet
|
||||
Was scarcely firm. At Rome my life was past
|
||||
Beneath the mild Augustus, in the time
|
||||
Of fabled deities and false. A bard
|
||||
Was I, and made Anchises' upright son
|
||||
The subject of my song, who came from Troy,
|
||||
When the flames prey'd on Ilium's haughty towers.
|
||||
But thou, say wherefore to such perils past
|
||||
Return'st thou? wherefore not this pleasant mount
|
||||
Ascendest, cause and source of all delight?"
|
||||
"And art thou then that Virgil, that well-spring,
|
||||
From which such copious floods of eloquence
|
||||
Have issued?" I with front abash'd replied.
|
||||
"Glory and light of all the tuneful train!
|
||||
May it avail me that I long with zeal
|
||||
Have sought thy volume, and with love immense
|
||||
Have conn'd it o'er. My master thou and guide!
|
||||
Thou he from whom alone I have deriv'd
|
||||
That style, which for its beauty into fame
|
||||
Exalts me. See the beast, from whom I fled.
|
||||
O save me from her, thou illustrious sage!"
|
||||
|
||||
"For every vein and pulse throughout my frame
|
||||
She hath made tremble." He, soon as he saw
|
||||
That I was weeping, answer'd, "Thou must needs
|
||||
Another way pursue, if thou wouldst 'scape
|
||||
From out that savage wilderness. This beast,
|
||||
At whom thou criest, her way will suffer none
|
||||
To pass, and no less hindrance makes than death:
|
||||
So bad and so accursed in her kind,
|
||||
That never sated is her ravenous will,
|
||||
Still after food more craving than before.
|
||||
To many an animal in wedlock vile
|
||||
She fastens, and shall yet to many more,
|
||||
Until that greyhound come, who shall destroy
|
||||
Her with sharp pain. He will not life support
|
||||
By earth nor its base metals, but by love,
|
||||
Wisdom, and virtue, and his land shall be
|
||||
The land 'twixt either Feltro. In his might
|
||||
Shall safety to Italia's plains arise,
|
||||
For whose fair realm, Camilla, virgin pure,
|
||||
Nisus, Euryalus, and Turnus fell.
|
||||
He with incessant chase through every town
|
||||
Shall worry, until he to hell at length
|
||||
Restore her, thence by envy first let loose.
|
||||
I for thy profit pond'ring now devise,
|
||||
That thou mayst follow me, and I thy guide
|
||||
Will lead thee hence through an eternal space,
|
||||
Where thou shalt hear despairing shrieks, and see
|
||||
Spirits of old tormented, who invoke
|
||||
A second death; and those next view, who dwell
|
||||
Content in fire, for that they hope to come,
|
||||
Whene'er the time may be, among the blest,
|
||||
Into whose regions if thou then desire
|
||||
T' ascend, a spirit worthier then I
|
||||
Must lead thee, in whose charge, when I depart,
|
||||
Thou shalt be left: for that Almighty King,
|
||||
Who reigns above, a rebel to his law,
|
||||
Adjudges me, and therefore hath decreed,
|
||||
That to his city none through me should come.
|
||||
He in all parts hath sway; there rules, there holds
|
||||
His citadel and throne. O happy those,
|
||||
Whom there he chooses!" I to him in few:
|
||||
"Bard! by that God, whom thou didst not adore,
|
||||
I do beseech thee (that this ill and worse
|
||||
I may escape) to lead me, where thou saidst,
|
||||
That I Saint Peter's gate may view, and those
|
||||
Who as thou tell'st, are in such dismal plight."
|
||||
|
||||
Onward he mov'd, I close his steps pursu'd.
|
|
@ -1,2 +0,0 @@
|
|||
/bin
|
||||
/gopath
|
|
@ -1,16 +0,0 @@
|
|||
language: go
|
||||
|
||||
go:
|
||||
- "1.9"
|
||||
- "1.10"
|
||||
|
||||
install:
|
||||
- go get -v -t github.com/coreos/go-oidc/...
|
||||
- go get golang.org/x/tools/cmd/cover
|
||||
- go get github.com/golang/lint/golint
|
||||
|
||||
script:
|
||||
- ./test
|
||||
|
||||
notifications:
|
||||
email: false
|
|
@ -1,71 +0,0 @@
|
|||
# How to Contribute
|
||||
|
||||
CoreOS projects are [Apache 2.0 licensed](LICENSE) and accept contributions via
|
||||
GitHub pull requests. This document outlines some of the conventions on
|
||||
development workflow, commit message formatting, contact points and other
|
||||
resources to make it easier to get your contribution accepted.
|
||||
|
||||
# Certificate of Origin
|
||||
|
||||
By contributing to this project you agree to the Developer Certificate of
|
||||
Origin (DCO). This document was created by the Linux Kernel community and is a
|
||||
simple statement that you, as a contributor, have the legal right to make the
|
||||
contribution. See the [DCO](DCO) file for details.
|
||||
|
||||
# Email and Chat
|
||||
|
||||
The project currently uses the general CoreOS email list and IRC channel:
|
||||
- Email: [coreos-dev](https://groups.google.com/forum/#!forum/coreos-dev)
|
||||
- IRC: #[coreos](irc://irc.freenode.org:6667/#coreos) IRC channel on freenode.org
|
||||
|
||||
Please avoid emailing maintainers found in the MAINTAINERS file directly. They
|
||||
are very busy and read the mailing lists.
|
||||
|
||||
## Getting Started
|
||||
|
||||
- Fork the repository on GitHub
|
||||
- Read the [README](README.md) for build and test instructions
|
||||
- Play with the project, submit bugs, submit patches!
|
||||
|
||||
## Contribution Flow
|
||||
|
||||
This is a rough outline of what a contributor's workflow looks like:
|
||||
|
||||
- Create a topic branch from where you want to base your work (usually master).
|
||||
- Make commits of logical units.
|
||||
- Make sure your commit messages are in the proper format (see below).
|
||||
- Push your changes to a topic branch in your fork of the repository.
|
||||
- Make sure the tests pass, and add any new tests as appropriate.
|
||||
- Submit a pull request to the original repository.
|
||||
|
||||
Thanks for your contributions!
|
||||
|
||||
### Format of the Commit Message
|
||||
|
||||
We follow a rough convention for commit messages that is designed to answer two
|
||||
questions: what changed and why. The subject line should feature the what and
|
||||
the body of the commit should describe the why.
|
||||
|
||||
```
|
||||
scripts: add the test-cluster command
|
||||
|
||||
this uses tmux to setup a test cluster that you can easily kill and
|
||||
start for debugging.
|
||||
|
||||
Fixes #38
|
||||
```
|
||||
|
||||
The format can be described more formally as follows:
|
||||
|
||||
```
|
||||
<subsystem>: <what changed>
|
||||
<BLANK LINE>
|
||||
<why this change was made>
|
||||
<BLANK LINE>
|
||||
<footer>
|
||||
```
|
||||
|
||||
The first line is the subject and should be no longer than 70 characters, the
|
||||
second line is always blank, and other lines should be wrapped at 80 characters.
|
||||
This allows the message to be easier to read on GitHub as well as in various
|
||||
git tools.
|
|
@ -1,36 +0,0 @@
|
|||
Developer Certificate of Origin
|
||||
Version 1.1
|
||||
|
||||
Copyright (C) 2004, 2006 The Linux Foundation and its contributors.
|
||||
660 York Street, Suite 102,
|
||||
San Francisco, CA 94110 USA
|
||||
|
||||
Everyone is permitted to copy and distribute verbatim copies of this
|
||||
license document, but changing it is not allowed.
|
||||
|
||||
|
||||
Developer's Certificate of Origin 1.1
|
||||
|
||||
By making a contribution to this project, I certify that:
|
||||
|
||||
(a) The contribution was created in whole or in part by me and I
|
||||
have the right to submit it under the open source license
|
||||
indicated in the file; or
|
||||
|
||||
(b) The contribution is based upon previous work that, to the best
|
||||
of my knowledge, is covered under an appropriate open source
|
||||
license and I have the right under that license to submit that
|
||||
work with modifications, whether created in whole or in part
|
||||
by me, under the same open source license (unless I am
|
||||
permitted to submit under a different license), as indicated
|
||||
in the file; or
|
||||
|
||||
(c) The contribution was provided directly to me by some other
|
||||
person who certified (a), (b) or (c) and I have not modified
|
||||
it.
|
||||
|
||||
(d) I understand and agree that this project and the contribution
|
||||
are public and that a record of the contribution (including all
|
||||
personal information I submit with it, including my sign-off) is
|
||||
maintained indefinitely and may be redistributed consistent with
|
||||
this project or the open source license(s) involved.
|
|
@ -1,3 +0,0 @@
|
|||
Eric Chiang <ericchiang@google.com> (@ericchiang)
|
||||
Mike Danese <mikedanese@google.com> (@mikedanese)
|
||||
Rithu Leena John <rjohn@redhat.com> (@rithujohn191)
|
|
@ -1,72 +0,0 @@
|
|||
# go-oidc
|
||||
|
||||
[![GoDoc](https://godoc.org/github.com/coreos/go-oidc?status.svg)](https://godoc.org/github.com/coreos/go-oidc)
|
||||
[![Build Status](https://travis-ci.org/coreos/go-oidc.png?branch=master)](https://travis-ci.org/coreos/go-oidc)
|
||||
|
||||
## OpenID Connect support for Go
|
||||
|
||||
This package enables OpenID Connect support for the [golang.org/x/oauth2](https://godoc.org/golang.org/x/oauth2) package.
|
||||
|
||||
```go
|
||||
provider, err := oidc.NewProvider(ctx, "https://accounts.google.com")
|
||||
if err != nil {
|
||||
// handle error
|
||||
}
|
||||
|
||||
// Configure an OpenID Connect aware OAuth2 client.
|
||||
oauth2Config := oauth2.Config{
|
||||
ClientID: clientID,
|
||||
ClientSecret: clientSecret,
|
||||
RedirectURL: redirectURL,
|
||||
|
||||
// Discovery returns the OAuth2 endpoints.
|
||||
Endpoint: provider.Endpoint(),
|
||||
|
||||
// "openid" is a required scope for OpenID Connect flows.
|
||||
Scopes: []string{oidc.ScopeOpenID, "profile", "email"},
|
||||
}
|
||||
```
|
||||
|
||||
OAuth2 redirects are unchanged.
|
||||
|
||||
```go
|
||||
func handleRedirect(w http.ResponseWriter, r *http.Request) {
|
||||
http.Redirect(w, r, oauth2Config.AuthCodeURL(state), http.StatusFound)
|
||||
}
|
||||
```
|
||||
|
||||
The on responses, the provider can be used to verify ID Tokens.
|
||||
|
||||
```go
|
||||
var verifier = provider.Verifier(&oidc.Config{ClientID: clientID})
|
||||
|
||||
func handleOAuth2Callback(w http.ResponseWriter, r *http.Request) {
|
||||
// Verify state and errors.
|
||||
|
||||
oauth2Token, err := oauth2Config.Exchange(ctx, r.URL.Query().Get("code"))
|
||||
if err != nil {
|
||||
// handle error
|
||||
}
|
||||
|
||||
// Extract the ID Token from OAuth2 token.
|
||||
rawIDToken, ok := oauth2Token.Extra("id_token").(string)
|
||||
if !ok {
|
||||
// handle missing token
|
||||
}
|
||||
|
||||
// Parse and verify ID Token payload.
|
||||
idToken, err := verifier.Verify(ctx, rawIDToken)
|
||||
if err != nil {
|
||||
// handle error
|
||||
}
|
||||
|
||||
// Extract custom claims
|
||||
var claims struct {
|
||||
Email string `json:"email"`
|
||||
Verified bool `json:"email_verified"`
|
||||
}
|
||||
if err := idToken.Claims(&claims); err != nil {
|
||||
// handle error
|
||||
}
|
||||
}
|
||||
```
|
|
@ -1,61 +0,0 @@
|
|||
## CoreOS Community Code of Conduct
|
||||
|
||||
### Contributor Code of Conduct
|
||||
|
||||
As contributors and maintainers of this project, and in the interest of
|
||||
fostering an open and welcoming community, we pledge to respect all people who
|
||||
contribute through reporting issues, posting feature requests, updating
|
||||
documentation, submitting pull requests or patches, and other activities.
|
||||
|
||||
We are committed to making participation in this project a harassment-free
|
||||
experience for everyone, regardless of level of experience, gender, gender
|
||||
identity and expression, sexual orientation, disability, personal appearance,
|
||||
body size, race, ethnicity, age, religion, or nationality.
|
||||
|
||||
Examples of unacceptable behavior by participants include:
|
||||
|
||||
* The use of sexualized language or imagery
|
||||
* Personal attacks
|
||||
* Trolling or insulting/derogatory comments
|
||||
* Public or private harassment
|
||||
* Publishing others' private information, such as physical or electronic addresses, without explicit permission
|
||||
* Other unethical or unprofessional conduct.
|
||||
|
||||
Project maintainers have the right and responsibility to remove, edit, or
|
||||
reject comments, commits, code, wiki edits, issues, and other contributions
|
||||
that are not aligned to this Code of Conduct. By adopting this Code of Conduct,
|
||||
project maintainers commit themselves to fairly and consistently applying these
|
||||
principles to every aspect of managing this project. Project maintainers who do
|
||||
not follow or enforce the Code of Conduct may be permanently removed from the
|
||||
project team.
|
||||
|
||||
This code of conduct applies both within project spaces and in public spaces
|
||||
when an individual is representing the project or its community.
|
||||
|
||||
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
||||
reported by contacting a project maintainer, Brandon Philips
|
||||
<brandon.philips@coreos.com>, and/or Rithu John <rithu.john@coreos.com>.
|
||||
|
||||
This Code of Conduct is adapted from the Contributor Covenant
|
||||
(http://contributor-covenant.org), version 1.2.0, available at
|
||||
http://contributor-covenant.org/version/1/2/0/
|
||||
|
||||
### CoreOS Events Code of Conduct
|
||||
|
||||
CoreOS events are working conferences intended for professional networking and
|
||||
collaboration in the CoreOS community. Attendees are expected to behave
|
||||
according to professional standards and in accordance with their employer’s
|
||||
policies on appropriate workplace behavior.
|
||||
|
||||
While at CoreOS events or related social networking opportunities, attendees
|
||||
should not engage in discriminatory or offensive speech or actions including
|
||||
but not limited to gender, sexuality, race, age, disability, or religion.
|
||||
Speakers should be especially aware of these concerns.
|
||||
|
||||
CoreOS does not condone any statements by speakers contrary to these standards.
|
||||
CoreOS reserves the right to deny entrance and/or eject from an event (without
|
||||
refund) any individual found to be engaging in discriminatory or offensive
|
||||
speech or actions.
|
||||
|
||||
Please bring any concerns to the immediate attention of designated on-site
|
||||
staff, Brandon Philips <brandon.philips@coreos.com>, and/or Rithu John <rithu.john@coreos.com>.
|
|
@ -1,20 +0,0 @@
|
|||
// +build !golint
|
||||
|
||||
// Don't lint this file. We don't want to have to add a comment to each constant.
|
||||
|
||||
package oidc
|
||||
|
||||
const (
|
||||
// JOSE asymmetric signing algorithm values as defined by RFC 7518
|
||||
//
|
||||
// see: https://tools.ietf.org/html/rfc7518#section-3.1
|
||||
RS256 = "RS256" // RSASSA-PKCS-v1.5 using SHA-256
|
||||
RS384 = "RS384" // RSASSA-PKCS-v1.5 using SHA-384
|
||||
RS512 = "RS512" // RSASSA-PKCS-v1.5 using SHA-512
|
||||
ES256 = "ES256" // ECDSA using P-256 and SHA-256
|
||||
ES384 = "ES384" // ECDSA using P-384 and SHA-384
|
||||
ES512 = "ES512" // ECDSA using P-521 and SHA-512
|
||||
PS256 = "PS256" // RSASSA-PSS using SHA256 and MGF1-SHA256
|
||||
PS384 = "PS384" // RSASSA-PSS using SHA384 and MGF1-SHA384
|
||||
PS512 = "PS512" // RSASSA-PSS using SHA512 and MGF1-SHA512
|
||||
)
|
|
@ -1,228 +0,0 @@
|
|||
package oidc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"sync"
|
||||
"time"
|
||||
|
||||
"github.com/pquerna/cachecontrol"
|
||||
jose "gopkg.in/square/go-jose.v2"
|
||||
)
|
||||
|
||||
// keysExpiryDelta is the allowed clock skew between a client and the OpenID Connect
|
||||
// server.
|
||||
//
|
||||
// When keys expire, they are valid for this amount of time after.
|
||||
//
|
||||
// If the keys have not expired, and an ID Token claims it was signed by a key not in
|
||||
// the cache, if and only if the keys expire in this amount of time, the keys will be
|
||||
// updated.
|
||||
const keysExpiryDelta = 30 * time.Second
|
||||
|
||||
// NewRemoteKeySet returns a KeySet that can validate JSON web tokens by using HTTP
|
||||
// GETs to fetch JSON web token sets hosted at a remote URL. This is automatically
|
||||
// used by NewProvider using the URLs returned by OpenID Connect discovery, but is
|
||||
// exposed for providers that don't support discovery or to prevent round trips to the
|
||||
// discovery URL.
|
||||
//
|
||||
// The returned KeySet is a long lived verifier that caches keys based on cache-control
|
||||
// headers. Reuse a common remote key set instead of creating new ones as needed.
|
||||
//
|
||||
// The behavior of the returned KeySet is undefined once the context is canceled.
|
||||
func NewRemoteKeySet(ctx context.Context, jwksURL string) KeySet {
|
||||
return newRemoteKeySet(ctx, jwksURL, time.Now)
|
||||
}
|
||||
|
||||
func newRemoteKeySet(ctx context.Context, jwksURL string, now func() time.Time) *remoteKeySet {
|
||||
if now == nil {
|
||||
now = time.Now
|
||||
}
|
||||
return &remoteKeySet{jwksURL: jwksURL, ctx: ctx, now: now}
|
||||
}
|
||||
|
||||
type remoteKeySet struct {
|
||||
jwksURL string
|
||||
ctx context.Context
|
||||
now func() time.Time
|
||||
|
||||
// guard all other fields
|
||||
mu sync.Mutex
|
||||
|
||||
// inflight suppresses parallel execution of updateKeys and allows
|
||||
// multiple goroutines to wait for its result.
|
||||
inflight *inflight
|
||||
|
||||
// A set of cached keys and their expiry.
|
||||
cachedKeys []jose.JSONWebKey
|
||||
expiry time.Time
|
||||
}
|
||||
|
||||
// inflight is used to wait on some in-flight request from multiple goroutines.
|
||||
type inflight struct {
|
||||
doneCh chan struct{}
|
||||
|
||||
keys []jose.JSONWebKey
|
||||
err error
|
||||
}
|
||||
|
||||
func newInflight() *inflight {
|
||||
return &inflight{doneCh: make(chan struct{})}
|
||||
}
|
||||
|
||||
// wait returns a channel that multiple goroutines can receive on. Once it returns
|
||||
// a value, the inflight request is done and result() can be inspected.
|
||||
func (i *inflight) wait() <-chan struct{} {
|
||||
return i.doneCh
|
||||
}
|
||||
|
||||
// done can only be called by a single goroutine. It records the result of the
|
||||
// inflight request and signals other goroutines that the result is safe to
|
||||
// inspect.
|
||||
func (i *inflight) done(keys []jose.JSONWebKey, err error) {
|
||||
i.keys = keys
|
||||
i.err = err
|
||||
close(i.doneCh)
|
||||
}
|
||||
|
||||
// result cannot be called until the wait() channel has returned a value.
|
||||
func (i *inflight) result() ([]jose.JSONWebKey, error) {
|
||||
return i.keys, i.err
|
||||
}
|
||||
|
||||
func (r *remoteKeySet) VerifySignature(ctx context.Context, jwt string) ([]byte, error) {
|
||||
jws, err := jose.ParseSigned(jwt)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("oidc: malformed jwt: %v", err)
|
||||
}
|
||||
return r.verify(ctx, jws)
|
||||
}
|
||||
|
||||
func (r *remoteKeySet) verify(ctx context.Context, jws *jose.JSONWebSignature) ([]byte, error) {
|
||||
// We don't support JWTs signed with multiple signatures.
|
||||
keyID := ""
|
||||
for _, sig := range jws.Signatures {
|
||||
keyID = sig.Header.KeyID
|
||||
break
|
||||
}
|
||||
|
||||
keys, expiry := r.keysFromCache()
|
||||
|
||||
// Don't check expiry yet. This optimizes for when the provider is unavailable.
|
||||
for _, key := range keys {
|
||||
if keyID == "" || key.KeyID == keyID {
|
||||
if payload, err := jws.Verify(&key); err == nil {
|
||||
return payload, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if !r.now().Add(keysExpiryDelta).After(expiry) {
|
||||
// Keys haven't expired, don't refresh.
|
||||
return nil, errors.New("failed to verify id token signature")
|
||||
}
|
||||
|
||||
keys, err := r.keysFromRemote(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("fetching keys %v", err)
|
||||
}
|
||||
|
||||
for _, key := range keys {
|
||||
if keyID == "" || key.KeyID == keyID {
|
||||
if payload, err := jws.Verify(&key); err == nil {
|
||||
return payload, nil
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil, errors.New("failed to verify id token signature")
|
||||
}
|
||||
|
||||
func (r *remoteKeySet) keysFromCache() (keys []jose.JSONWebKey, expiry time.Time) {
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
return r.cachedKeys, r.expiry
|
||||
}
|
||||
|
||||
// keysFromRemote syncs the key set from the remote set, records the values in the
|
||||
// cache, and returns the key set.
|
||||
func (r *remoteKeySet) keysFromRemote(ctx context.Context) ([]jose.JSONWebKey, error) {
|
||||
// Need to lock to inspect the inflight request field.
|
||||
r.mu.Lock()
|
||||
// If there's not a current inflight request, create one.
|
||||
if r.inflight == nil {
|
||||
r.inflight = newInflight()
|
||||
|
||||
// This goroutine has exclusive ownership over the current inflight
|
||||
// request. It releases the resource by nil'ing the inflight field
|
||||
// once the goroutine is done.
|
||||
go func() {
|
||||
// Sync keys and finish inflight when that's done.
|
||||
keys, expiry, err := r.updateKeys()
|
||||
|
||||
r.inflight.done(keys, err)
|
||||
|
||||
// Lock to update the keys and indicate that there is no longer an
|
||||
// inflight request.
|
||||
r.mu.Lock()
|
||||
defer r.mu.Unlock()
|
||||
|
||||
if err == nil {
|
||||
r.cachedKeys = keys
|
||||
r.expiry = expiry
|
||||
}
|
||||
|
||||
// Free inflight so a different request can run.
|
||||
r.inflight = nil
|
||||
}()
|
||||
}
|
||||
inflight := r.inflight
|
||||
r.mu.Unlock()
|
||||
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return nil, ctx.Err()
|
||||
case <-inflight.wait():
|
||||
return inflight.result()
|
||||
}
|
||||
}
|
||||
|
||||
func (r *remoteKeySet) updateKeys() ([]jose.JSONWebKey, time.Time, error) {
|
||||
req, err := http.NewRequest("GET", r.jwksURL, nil)
|
||||
if err != nil {
|
||||
return nil, time.Time{}, fmt.Errorf("oidc: can't create request: %v", err)
|
||||
}
|
||||
|
||||
resp, err := doRequest(r.ctx, req)
|
||||
if err != nil {
|
||||
return nil, time.Time{}, fmt.Errorf("oidc: get keys failed %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, time.Time{}, fmt.Errorf("unable to read response body: %v", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, time.Time{}, fmt.Errorf("oidc: get keys failed: %s %s", resp.Status, body)
|
||||
}
|
||||
|
||||
var keySet jose.JSONWebKeySet
|
||||
err = unmarshalResp(resp, body, &keySet)
|
||||
if err != nil {
|
||||
return nil, time.Time{}, fmt.Errorf("oidc: failed to decode keys: %v %s", err, body)
|
||||
}
|
||||
|
||||
// If the server doesn't provide cache control headers, assume the
|
||||
// keys expire immediately.
|
||||
expiry := r.now()
|
||||
|
||||
_, e, err := cachecontrol.CachableResponse(req, resp, cachecontrol.Options{})
|
||||
if err == nil && e.After(expiry) {
|
||||
expiry = e
|
||||
}
|
||||
return keySet.Keys, expiry, nil
|
||||
}
|
|
@ -1,384 +0,0 @@
|
|||
// Package oidc implements OpenID Connect client logic for the golang.org/x/oauth2 package.
|
||||
package oidc
|
||||
|
||||
import (
|
||||
"context"
|
||||
"crypto/sha256"
|
||||
"crypto/sha512"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"hash"
|
||||
"io/ioutil"
|
||||
"mime"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"golang.org/x/oauth2"
|
||||
jose "gopkg.in/square/go-jose.v2"
|
||||
)
|
||||
|
||||
const (
|
||||
// ScopeOpenID is the mandatory scope for all OpenID Connect OAuth2 requests.
|
||||
ScopeOpenID = "openid"
|
||||
|
||||
// ScopeOfflineAccess is an optional scope defined by OpenID Connect for requesting
|
||||
// OAuth2 refresh tokens.
|
||||
//
|
||||
// Support for this scope differs between OpenID Connect providers. For instance
|
||||
// Google rejects it, favoring appending "access_type=offline" as part of the
|
||||
// authorization request instead.
|
||||
//
|
||||
// See: https://openid.net/specs/openid-connect-core-1_0.html#OfflineAccess
|
||||
ScopeOfflineAccess = "offline_access"
|
||||
)
|
||||
|
||||
var (
|
||||
errNoAtHash = errors.New("id token did not have an access token hash")
|
||||
errInvalidAtHash = errors.New("access token hash does not match value in ID token")
|
||||
)
|
||||
|
||||
// ClientContext returns a new Context that carries the provided HTTP client.
|
||||
//
|
||||
// This method sets the same context key used by the golang.org/x/oauth2 package,
|
||||
// so the returned context works for that package too.
|
||||
//
|
||||
// myClient := &http.Client{}
|
||||
// ctx := oidc.ClientContext(parentContext, myClient)
|
||||
//
|
||||
// // This will use the custom client
|
||||
// provider, err := oidc.NewProvider(ctx, "https://accounts.example.com")
|
||||
//
|
||||
func ClientContext(ctx context.Context, client *http.Client) context.Context {
|
||||
return context.WithValue(ctx, oauth2.HTTPClient, client)
|
||||
}
|
||||
|
||||
func doRequest(ctx context.Context, req *http.Request) (*http.Response, error) {
|
||||
client := http.DefaultClient
|
||||
if c, ok := ctx.Value(oauth2.HTTPClient).(*http.Client); ok {
|
||||
client = c
|
||||
}
|
||||
return client.Do(req.WithContext(ctx))
|
||||
}
|
||||
|
||||
// Provider represents an OpenID Connect server's configuration.
|
||||
type Provider struct {
|
||||
issuer string
|
||||
authURL string
|
||||
tokenURL string
|
||||
userInfoURL string
|
||||
|
||||
// Raw claims returned by the server.
|
||||
rawClaims []byte
|
||||
|
||||
remoteKeySet KeySet
|
||||
}
|
||||
|
||||
type cachedKeys struct {
|
||||
keys []jose.JSONWebKey
|
||||
expiry time.Time
|
||||
}
|
||||
|
||||
type providerJSON struct {
|
||||
Issuer string `json:"issuer"`
|
||||
AuthURL string `json:"authorization_endpoint"`
|
||||
TokenURL string `json:"token_endpoint"`
|
||||
JWKSURL string `json:"jwks_uri"`
|
||||
UserInfoURL string `json:"userinfo_endpoint"`
|
||||
}
|
||||
|
||||
// NewProvider uses the OpenID Connect discovery mechanism to construct a Provider.
|
||||
//
|
||||
// The issuer is the URL identifier for the service. For example: "https://accounts.google.com"
|
||||
// or "https://login.salesforce.com".
|
||||
func NewProvider(ctx context.Context, issuer string) (*Provider, error) {
|
||||
wellKnown := strings.TrimSuffix(issuer, "/") + "/.well-known/openid-configuration"
|
||||
req, err := http.NewRequest("GET", wellKnown, nil)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
resp, err := doRequest(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to read response body: %v", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, fmt.Errorf("%s: %s", resp.Status, body)
|
||||
}
|
||||
|
||||
var p providerJSON
|
||||
err = unmarshalResp(resp, body, &p)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("oidc: failed to decode provider discovery object: %v", err)
|
||||
}
|
||||
|
||||
if p.Issuer != issuer {
|
||||
return nil, fmt.Errorf("oidc: issuer did not match the issuer returned by provider, expected %q got %q", issuer, p.Issuer)
|
||||
}
|
||||
return &Provider{
|
||||
issuer: p.Issuer,
|
||||
authURL: p.AuthURL,
|
||||
tokenURL: p.TokenURL,
|
||||
userInfoURL: p.UserInfoURL,
|
||||
rawClaims: body,
|
||||
remoteKeySet: NewRemoteKeySet(ctx, p.JWKSURL),
|
||||
}, nil
|
||||
}
|
||||
|
||||
// Claims unmarshals raw fields returned by the server during discovery.
|
||||
//
|
||||
// var claims struct {
|
||||
// ScopesSupported []string `json:"scopes_supported"`
|
||||
// ClaimsSupported []string `json:"claims_supported"`
|
||||
// }
|
||||
//
|
||||
// if err := provider.Claims(&claims); err != nil {
|
||||
// // handle unmarshaling error
|
||||
// }
|
||||
//
|
||||
// For a list of fields defined by the OpenID Connect spec see:
|
||||
// https://openid.net/specs/openid-connect-discovery-1_0.html#ProviderMetadata
|
||||
func (p *Provider) Claims(v interface{}) error {
|
||||
if p.rawClaims == nil {
|
||||
return errors.New("oidc: claims not set")
|
||||
}
|
||||
return json.Unmarshal(p.rawClaims, v)
|
||||
}
|
||||
|
||||
// Endpoint returns the OAuth2 auth and token endpoints for the given provider.
|
||||
func (p *Provider) Endpoint() oauth2.Endpoint {
|
||||
return oauth2.Endpoint{AuthURL: p.authURL, TokenURL: p.tokenURL}
|
||||
}
|
||||
|
||||
// UserInfo represents the OpenID Connect userinfo claims.
|
||||
type UserInfo struct {
|
||||
Subject string `json:"sub"`
|
||||
Profile string `json:"profile"`
|
||||
Email string `json:"email"`
|
||||
EmailVerified bool `json:"email_verified"`
|
||||
|
||||
claims []byte
|
||||
}
|
||||
|
||||
// Claims unmarshals the raw JSON object claims into the provided object.
|
||||
func (u *UserInfo) Claims(v interface{}) error {
|
||||
if u.claims == nil {
|
||||
return errors.New("oidc: claims not set")
|
||||
}
|
||||
return json.Unmarshal(u.claims, v)
|
||||
}
|
||||
|
||||
// UserInfo uses the token source to query the provider's user info endpoint.
|
||||
func (p *Provider) UserInfo(ctx context.Context, tokenSource oauth2.TokenSource) (*UserInfo, error) {
|
||||
if p.userInfoURL == "" {
|
||||
return nil, errors.New("oidc: user info endpoint is not supported by this provider")
|
||||
}
|
||||
|
||||
req, err := http.NewRequest("GET", p.userInfoURL, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("oidc: create GET request: %v", err)
|
||||
}
|
||||
|
||||
token, err := tokenSource.Token()
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("oidc: get access token: %v", err)
|
||||
}
|
||||
token.SetAuthHeader(req)
|
||||
|
||||
resp, err := doRequest(ctx, req)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, fmt.Errorf("%s: %s", resp.Status, body)
|
||||
}
|
||||
|
||||
var userInfo UserInfo
|
||||
if err := json.Unmarshal(body, &userInfo); err != nil {
|
||||
return nil, fmt.Errorf("oidc: failed to decode userinfo: %v", err)
|
||||
}
|
||||
userInfo.claims = body
|
||||
return &userInfo, nil
|
||||
}
|
||||
|
||||
// IDToken is an OpenID Connect extension that provides a predictable representation
|
||||
// of an authorization event.
|
||||
//
|
||||
// The ID Token only holds fields OpenID Connect requires. To access additional
|
||||
// claims returned by the server, use the Claims method.
|
||||
type IDToken struct {
|
||||
// The URL of the server which issued this token. OpenID Connect
|
||||
// requires this value always be identical to the URL used for
|
||||
// initial discovery.
|
||||
//
|
||||
// Note: Because of a known issue with Google Accounts' implementation
|
||||
// this value may differ when using Google.
|
||||
//
|
||||
// See: https://developers.google.com/identity/protocols/OpenIDConnect#obtainuserinfo
|
||||
Issuer string
|
||||
|
||||
// The client ID, or set of client IDs, that this token is issued for. For
|
||||
// common uses, this is the client that initialized the auth flow.
|
||||
//
|
||||
// This package ensures the audience contains an expected value.
|
||||
Audience []string
|
||||
|
||||
// A unique string which identifies the end user.
|
||||
Subject string
|
||||
|
||||
// Expiry of the token. Ths package will not process tokens that have
|
||||
// expired unless that validation is explicitly turned off.
|
||||
Expiry time.Time
|
||||
// When the token was issued by the provider.
|
||||
IssuedAt time.Time
|
||||
|
||||
// Initial nonce provided during the authentication redirect.
|
||||
//
|
||||
// This package does NOT provided verification on the value of this field
|
||||
// and it's the user's responsibility to ensure it contains a valid value.
|
||||
Nonce string
|
||||
|
||||
// at_hash claim, if set in the ID token. Callers can verify an access token
|
||||
// that corresponds to the ID token using the VerifyAccessToken method.
|
||||
AccessTokenHash string
|
||||
|
||||
// signature algorithm used for ID token, needed to compute a verification hash of an
|
||||
// access token
|
||||
sigAlgorithm string
|
||||
|
||||
// Raw payload of the id_token.
|
||||
claims []byte
|
||||
|
||||
// Map of distributed claim names to claim sources
|
||||
distributedClaims map[string]claimSource
|
||||
}
|
||||
|
||||
// Claims unmarshals the raw JSON payload of the ID Token into a provided struct.
|
||||
//
|
||||
// idToken, err := idTokenVerifier.Verify(rawIDToken)
|
||||
// if err != nil {
|
||||
// // handle error
|
||||
// }
|
||||
// var claims struct {
|
||||
// Email string `json:"email"`
|
||||
// EmailVerified bool `json:"email_verified"`
|
||||
// }
|
||||
// if err := idToken.Claims(&claims); err != nil {
|
||||
// // handle error
|
||||
// }
|
||||
//
|
||||
func (i *IDToken) Claims(v interface{}) error {
|
||||
if i.claims == nil {
|
||||
return errors.New("oidc: claims not set")
|
||||
}
|
||||
return json.Unmarshal(i.claims, v)
|
||||
}
|
||||
|
||||
// VerifyAccessToken verifies that the hash of the access token that corresponds to the iD token
|
||||
// matches the hash in the id token. It returns an error if the hashes don't match.
|
||||
// It is the caller's responsibility to ensure that the optional access token hash is present for the ID token
|
||||
// before calling this method. See https://openid.net/specs/openid-connect-core-1_0.html#CodeIDToken
|
||||
func (i *IDToken) VerifyAccessToken(accessToken string) error {
|
||||
if i.AccessTokenHash == "" {
|
||||
return errNoAtHash
|
||||
}
|
||||
var h hash.Hash
|
||||
switch i.sigAlgorithm {
|
||||
case RS256, ES256, PS256:
|
||||
h = sha256.New()
|
||||
case RS384, ES384, PS384:
|
||||
h = sha512.New384()
|
||||
case RS512, ES512, PS512:
|
||||
h = sha512.New()
|
||||
default:
|
||||
return fmt.Errorf("oidc: unsupported signing algorithm %q", i.sigAlgorithm)
|
||||
}
|
||||
h.Write([]byte(accessToken)) // hash documents that Write will never return an error
|
||||
sum := h.Sum(nil)[:h.Size()/2]
|
||||
actual := base64.RawURLEncoding.EncodeToString(sum)
|
||||
if actual != i.AccessTokenHash {
|
||||
return errInvalidAtHash
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
type idToken struct {
|
||||
Issuer string `json:"iss"`
|
||||
Subject string `json:"sub"`
|
||||
Audience audience `json:"aud"`
|
||||
Expiry jsonTime `json:"exp"`
|
||||
IssuedAt jsonTime `json:"iat"`
|
||||
Nonce string `json:"nonce"`
|
||||
AtHash string `json:"at_hash"`
|
||||
ClaimNames map[string]string `json:"_claim_names"`
|
||||
ClaimSources map[string]claimSource `json:"_claim_sources"`
|
||||
}
|
||||
|
||||
type claimSource struct {
|
||||
Endpoint string `json:"endpoint"`
|
||||
AccessToken string `json:"access_token"`
|
||||
}
|
||||
|
||||
type audience []string
|
||||
|
||||
func (a *audience) UnmarshalJSON(b []byte) error {
|
||||
var s string
|
||||
if json.Unmarshal(b, &s) == nil {
|
||||
*a = audience{s}
|
||||
return nil
|
||||
}
|
||||
var auds []string
|
||||
if err := json.Unmarshal(b, &auds); err != nil {
|
||||
return err
|
||||
}
|
||||
*a = audience(auds)
|
||||
return nil
|
||||
}
|
||||
|
||||
type jsonTime time.Time
|
||||
|
||||
func (j *jsonTime) UnmarshalJSON(b []byte) error {
|
||||
var n json.Number
|
||||
if err := json.Unmarshal(b, &n); err != nil {
|
||||
return err
|
||||
}
|
||||
var unix int64
|
||||
|
||||
if t, err := n.Int64(); err == nil {
|
||||
unix = t
|
||||
} else {
|
||||
f, err := n.Float64()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
unix = int64(f)
|
||||
}
|
||||
*j = jsonTime(time.Unix(unix, 0))
|
||||
return nil
|
||||
}
|
||||
|
||||
func unmarshalResp(r *http.Response, body []byte, v interface{}) error {
|
||||
err := json.Unmarshal(body, &v)
|
||||
if err == nil {
|
||||
return nil
|
||||
}
|
||||
ct := r.Header.Get("Content-Type")
|
||||
mediaType, _, parseErr := mime.ParseMediaType(ct)
|
||||
if parseErr == nil && mediaType == "application/json" {
|
||||
return fmt.Errorf("got Content-Type = application/json, but could not unmarshal as JSON: %v", err)
|
||||
}
|
||||
return fmt.Errorf("expected Content-Type = application/json, got %q: %v", ct, err)
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
#!/bin/bash
|
||||
|
||||
set -e
|
||||
|
||||
# Filter out any files with a !golint build tag.
|
||||
LINTABLE=$( go list -tags=golint -f '
|
||||
{{- range $i, $file := .GoFiles -}}
|
||||
{{ $file }} {{ end }}
|
||||
{{ range $i, $file := .TestGoFiles -}}
|
||||
{{ $file }} {{ end }}' github.com/coreos/go-oidc )
|
||||
|
||||
go test -v -i -race github.com/coreos/go-oidc/...
|
||||
go test -v -race github.com/coreos/go-oidc/...
|
||||
golint -set_exit_status $LINTABLE
|
||||
go vet github.com/coreos/go-oidc/...
|
||||
go build -v ./example/...
|
|
@ -1,316 +0,0 @@
|
|||
package oidc
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/base64"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"golang.org/x/oauth2"
|
||||
jose "gopkg.in/square/go-jose.v2"
|
||||
)
|
||||
|
||||
const (
|
||||
issuerGoogleAccounts = "https://accounts.google.com"
|
||||
issuerGoogleAccountsNoScheme = "accounts.google.com"
|
||||
)
|
||||
|
||||
// KeySet is a set of publc JSON Web Keys that can be used to validate the signature
|
||||
// of JSON web tokens. This is expected to be backed by a remote key set through
|
||||
// provider metadata discovery or an in-memory set of keys delivered out-of-band.
|
||||
type KeySet interface {
|
||||
// VerifySignature parses the JSON web token, verifies the signature, and returns
|
||||
// the raw payload. Header and claim fields are validated by other parts of the
|
||||
// package. For example, the KeySet does not need to check values such as signature
|
||||
// algorithm, issuer, and audience since the IDTokenVerifier validates these values
|
||||
// independently.
|
||||
//
|
||||
// If VerifySignature makes HTTP requests to verify the token, it's expected to
|
||||
// use any HTTP client associated with the context through ClientContext.
|
||||
VerifySignature(ctx context.Context, jwt string) (payload []byte, err error)
|
||||
}
|
||||
|
||||
// IDTokenVerifier provides verification for ID Tokens.
|
||||
type IDTokenVerifier struct {
|
||||
keySet KeySet
|
||||
config *Config
|
||||
issuer string
|
||||
}
|
||||
|
||||
// NewVerifier returns a verifier manually constructed from a key set and issuer URL.
|
||||
//
|
||||
// It's easier to use provider discovery to construct an IDTokenVerifier than creating
|
||||
// one directly. This method is intended to be used with provider that don't support
|
||||
// metadata discovery, or avoiding round trips when the key set URL is already known.
|
||||
//
|
||||
// This constructor can be used to create a verifier directly using the issuer URL and
|
||||
// JSON Web Key Set URL without using discovery:
|
||||
//
|
||||
// keySet := oidc.NewRemoteKeySet(ctx, "https://www.googleapis.com/oauth2/v3/certs")
|
||||
// verifier := oidc.NewVerifier("https://accounts.google.com", keySet, config)
|
||||
//
|
||||
// Since KeySet is an interface, this constructor can also be used to supply custom
|
||||
// public key sources. For example, if a user wanted to supply public keys out-of-band
|
||||
// and hold them statically in-memory:
|
||||
//
|
||||
// // Custom KeySet implementation.
|
||||
// keySet := newStatisKeySet(publicKeys...)
|
||||
//
|
||||
// // Verifier uses the custom KeySet implementation.
|
||||
// verifier := oidc.NewVerifier("https://auth.example.com", keySet, config)
|
||||
//
|
||||
func NewVerifier(issuerURL string, keySet KeySet, config *Config) *IDTokenVerifier {
|
||||
return &IDTokenVerifier{keySet: keySet, config: config, issuer: issuerURL}
|
||||
}
|
||||
|
||||
// Config is the configuration for an IDTokenVerifier.
|
||||
type Config struct {
|
||||
// Expected audience of the token. For a majority of the cases this is expected to be
|
||||
// the ID of the client that initialized the login flow. It may occasionally differ if
|
||||
// the provider supports the authorizing party (azp) claim.
|
||||
//
|
||||
// If not provided, users must explicitly set SkipClientIDCheck.
|
||||
ClientID string
|
||||
// If specified, only this set of algorithms may be used to sign the JWT.
|
||||
//
|
||||
// Since many providers only support RS256, SupportedSigningAlgs defaults to this value.
|
||||
SupportedSigningAlgs []string
|
||||
|
||||
// If true, no ClientID check performed. Must be true if ClientID field is empty.
|
||||
SkipClientIDCheck bool
|
||||
// If true, token expiry is not checked.
|
||||
SkipExpiryCheck bool
|
||||
|
||||
// SkipIssuerCheck is intended for specialized cases where the the caller wishes to
|
||||
// defer issuer validation. When enabled, callers MUST independently verify the Token's
|
||||
// Issuer is a known good value.
|
||||
//
|
||||
// Mismatched issuers often indicate client mis-configuration. If mismatches are
|
||||
// unexpected, evaluate if the provided issuer URL is incorrect instead of enabling
|
||||
// this option.
|
||||
SkipIssuerCheck bool
|
||||
|
||||
// Time function to check Token expiry. Defaults to time.Now
|
||||
Now func() time.Time
|
||||
}
|
||||
|
||||
// Verifier returns an IDTokenVerifier that uses the provider's key set to verify JWTs.
|
||||
//
|
||||
// The returned IDTokenVerifier is tied to the Provider's context and its behavior is
|
||||
// undefined once the Provider's context is canceled.
|
||||
func (p *Provider) Verifier(config *Config) *IDTokenVerifier {
|
||||
return NewVerifier(p.issuer, p.remoteKeySet, config)
|
||||
}
|
||||
|
||||
func parseJWT(p string) ([]byte, error) {
|
||||
parts := strings.Split(p, ".")
|
||||
if len(parts) < 2 {
|
||||
return nil, fmt.Errorf("oidc: malformed jwt, expected 3 parts got %d", len(parts))
|
||||
}
|
||||
payload, err := base64.RawURLEncoding.DecodeString(parts[1])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("oidc: malformed jwt payload: %v", err)
|
||||
}
|
||||
return payload, nil
|
||||
}
|
||||
|
||||
func contains(sli []string, ele string) bool {
|
||||
for _, s := range sli {
|
||||
if s == ele {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// Returns the Claims from the distributed JWT token
|
||||
func resolveDistributedClaim(ctx context.Context, verifier *IDTokenVerifier, src claimSource) ([]byte, error) {
|
||||
req, err := http.NewRequest("GET", src.Endpoint, nil)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("malformed request: %v", err)
|
||||
}
|
||||
if src.AccessToken != "" {
|
||||
req.Header.Set("Authorization", "Bearer "+src.AccessToken)
|
||||
}
|
||||
|
||||
resp, err := doRequest(ctx, req)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("oidc: Request to endpoint failed: %v", err)
|
||||
}
|
||||
defer resp.Body.Close()
|
||||
|
||||
body, err := ioutil.ReadAll(resp.Body)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("unable to read response body: %v", err)
|
||||
}
|
||||
|
||||
if resp.StatusCode != http.StatusOK {
|
||||
return nil, fmt.Errorf("oidc: request failed: %v", resp.StatusCode)
|
||||
}
|
||||
|
||||
token, err := verifier.Verify(ctx, string(body))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("malformed response body: %v", err)
|
||||
}
|
||||
|
||||
return token.claims, nil
|
||||
}
|
||||
|
||||
func parseClaim(raw []byte, name string, v interface{}) error {
|
||||
var parsed map[string]json.RawMessage
|
||||
if err := json.Unmarshal(raw, &parsed); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
val, ok := parsed[name]
|
||||
if !ok {
|
||||
return fmt.Errorf("claim doesn't exist: %s", name)
|
||||
}
|
||||
|
||||
return json.Unmarshal([]byte(val), v)
|
||||
}
|
||||
|
||||
// Verify parses a raw ID Token, verifies it's been signed by the provider, preforms
|
||||
// any additional checks depending on the Config, and returns the payload.
|
||||
//
|
||||
// Verify does NOT do nonce validation, which is the callers responsibility.
|
||||
//
|
||||
// See: https://openid.net/specs/openid-connect-core-1_0.html#IDTokenValidation
|
||||
//
|
||||
// oauth2Token, err := oauth2Config.Exchange(ctx, r.URL.Query().Get("code"))
|
||||
// if err != nil {
|
||||
// // handle error
|
||||
// }
|
||||
//
|
||||
// // Extract the ID Token from oauth2 token.
|
||||
// rawIDToken, ok := oauth2Token.Extra("id_token").(string)
|
||||
// if !ok {
|
||||
// // handle error
|
||||
// }
|
||||
//
|
||||
// token, err := verifier.Verify(ctx, rawIDToken)
|
||||
//
|
||||
func (v *IDTokenVerifier) Verify(ctx context.Context, rawIDToken string) (*IDToken, error) {
|
||||
jws, err := jose.ParseSigned(rawIDToken)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("oidc: malformed jwt: %v", err)
|
||||
}
|
||||
|
||||
// Throw out tokens with invalid claims before trying to verify the token. This lets
|
||||
// us do cheap checks before possibly re-syncing keys.
|
||||
payload, err := parseJWT(rawIDToken)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("oidc: malformed jwt: %v", err)
|
||||
}
|
||||
var token idToken
|
||||
if err := json.Unmarshal(payload, &token); err != nil {
|
||||
return nil, fmt.Errorf("oidc: failed to unmarshal claims: %v", err)
|
||||
}
|
||||
|
||||
distributedClaims := make(map[string]claimSource)
|
||||
|
||||
//step through the token to map claim names to claim sources"
|
||||
for cn, src := range token.ClaimNames {
|
||||
if src == "" {
|
||||
return nil, fmt.Errorf("oidc: failed to obtain source from claim name")
|
||||
}
|
||||
s, ok := token.ClaimSources[src]
|
||||
if !ok {
|
||||
return nil, fmt.Errorf("oidc: source does not exist")
|
||||
}
|
||||
distributedClaims[cn] = s
|
||||
}
|
||||
|
||||
t := &IDToken{
|
||||
Issuer: token.Issuer,
|
||||
Subject: token.Subject,
|
||||
Audience: []string(token.Audience),
|
||||
Expiry: time.Time(token.Expiry),
|
||||
IssuedAt: time.Time(token.IssuedAt),
|
||||
Nonce: token.Nonce,
|
||||
AccessTokenHash: token.AtHash,
|
||||
claims: payload,
|
||||
distributedClaims: distributedClaims,
|
||||
}
|
||||
|
||||
// Check issuer.
|
||||
if !v.config.SkipIssuerCheck && t.Issuer != v.issuer {
|
||||
// Google sometimes returns "accounts.google.com" as the issuer claim instead of
|
||||
// the required "https://accounts.google.com". Detect this case and allow it only
|
||||
// for Google.
|
||||
//
|
||||
// We will not add hooks to let other providers go off spec like this.
|
||||
if !(v.issuer == issuerGoogleAccounts && t.Issuer == issuerGoogleAccountsNoScheme) {
|
||||
return nil, fmt.Errorf("oidc: id token issued by a different provider, expected %q got %q", v.issuer, t.Issuer)
|
||||
}
|
||||
}
|
||||
|
||||
// If a client ID has been provided, make sure it's part of the audience. SkipClientIDCheck must be true if ClientID is empty.
|
||||
//
|
||||
// This check DOES NOT ensure that the ClientID is the party to which the ID Token was issued (i.e. Authorized party).
|
||||
if !v.config.SkipClientIDCheck {
|
||||
if v.config.ClientID != "" {
|
||||
if !contains(t.Audience, v.config.ClientID) {
|
||||
return nil, fmt.Errorf("oidc: expected audience %q got %q", v.config.ClientID, t.Audience)
|
||||
}
|
||||
} else {
|
||||
return nil, fmt.Errorf("oidc: invalid configuration, clientID must be provided or SkipClientIDCheck must be set")
|
||||
}
|
||||
}
|
||||
|
||||
// If a SkipExpiryCheck is false, make sure token is not expired.
|
||||
if !v.config.SkipExpiryCheck {
|
||||
now := time.Now
|
||||
if v.config.Now != nil {
|
||||
now = v.config.Now
|
||||
}
|
||||
|
||||
if t.Expiry.Before(now()) {
|
||||
return nil, fmt.Errorf("oidc: token is expired (Token Expiry: %v)", t.Expiry)
|
||||
}
|
||||
}
|
||||
|
||||
switch len(jws.Signatures) {
|
||||
case 0:
|
||||
return nil, fmt.Errorf("oidc: id token not signed")
|
||||
case 1:
|
||||
default:
|
||||
return nil, fmt.Errorf("oidc: multiple signatures on id token not supported")
|
||||
}
|
||||
|
||||
sig := jws.Signatures[0]
|
||||
supportedSigAlgs := v.config.SupportedSigningAlgs
|
||||
if len(supportedSigAlgs) == 0 {
|
||||
supportedSigAlgs = []string{RS256}
|
||||
}
|
||||
|
||||
if !contains(supportedSigAlgs, sig.Header.Algorithm) {
|
||||
return nil, fmt.Errorf("oidc: id token signed with unsupported algorithm, expected %q got %q", supportedSigAlgs, sig.Header.Algorithm)
|
||||
}
|
||||
|
||||
t.sigAlgorithm = sig.Header.Algorithm
|
||||
|
||||
gotPayload, err := v.keySet.VerifySignature(ctx, rawIDToken)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to verify signature: %v", err)
|
||||
}
|
||||
|
||||
// Ensure that the payload returned by the square actually matches the payload parsed earlier.
|
||||
if !bytes.Equal(gotPayload, payload) {
|
||||
return nil, errors.New("oidc: internal error, payload parsed did not match previous payload")
|
||||
}
|
||||
|
||||
return t, nil
|
||||
}
|
||||
|
||||
// Nonce returns an auth code option which requires the ID Token created by the
|
||||
// OpenID Connect provider to contain the specified nonce.
|
||||
func Nonce(nonce string) oauth2.AuthCodeOption {
|
||||
return oauth2.SetAuthURLParam("nonce", nonce)
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
Copyright (c) 2012 The Go Authors. All rights reserved.
|
||||
|
||||
Redistribution and use in source and binary forms, with or without
|
||||
modification, are permitted provided that the following conditions are
|
||||
met:
|
||||
|
||||
* Redistributions of source code must retain the above copyright
|
||||
notice, this list of conditions and the following disclaimer.
|
||||
* Redistributions in binary form must reproduce the above
|
||||
copyright notice, this list of conditions and the following disclaimer
|
||||
in the documentation and/or other materials provided with the
|
||||
distribution.
|
||||
* Neither the name of Google Inc. nor the names of its
|
||||
contributors may be used to endorse or promote products derived from
|
||||
this software without specific prior written permission.
|
||||
|
||||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
||||
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
||||
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
||||
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
||||
OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
||||
SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
||||
LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
||||
DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
||||
THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
||||
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
@ -1,276 +0,0 @@
|
|||
# A pure Go MSSQL driver for Go's database/sql package
|
||||
|
||||
[![GoDoc](https://godoc.org/github.com/denisenkom/go-mssqldb?status.svg)](http://godoc.org/github.com/denisenkom/go-mssqldb)
|
||||
[![Build status](https://ci.appveyor.com/api/projects/status/jrln8cs62wj9i0a2?svg=true)](https://ci.appveyor.com/project/denisenkom/go-mssqldb)
|
||||
[![codecov](https://codecov.io/gh/denisenkom/go-mssqldb/branch/master/graph/badge.svg)](https://codecov.io/gh/denisenkom/go-mssqldb)
|
||||
|
||||
## Install
|
||||
|
||||
Requires Go 1.8 or above.
|
||||
|
||||
Install with `go get github.com/denisenkom/go-mssqldb` .
|
||||
|
||||
## Connection Parameters and DSN
|
||||
|
||||
The recommended connection string uses a URL format:
|
||||
`sqlserver://username:password@host/instance?param1=value¶m2=value`
|
||||
Other supported formats are listed below.
|
||||
|
||||
### Common parameters:
|
||||
|
||||
* `user id` - enter the SQL Server Authentication user id or the Windows Authentication user id in the DOMAIN\User format. On Windows, if user id is empty or missing Single-Sign-On is used.
|
||||
* `password`
|
||||
* `database`
|
||||
* `connection timeout` - in seconds (default is 0 for no timeout), set to 0 for no timeout. Recommended to set to 0 and use context to manage query and connection timeouts.
|
||||
* `dial timeout` - in seconds (default is 15), set to 0 for no timeout
|
||||
* `encrypt`
|
||||
* `disable` - Data send between client and server is not encrypted.
|
||||
* `false` - Data sent between client and server is not encrypted beyond the login packet. (Default)
|
||||
* `true` - Data sent between client and server is encrypted.
|
||||
* `app name` - The application name (default is go-mssqldb)
|
||||
|
||||
### Connection parameters for ODBC and ADO style connection strings:
|
||||
|
||||
* `server` - host or host\instance (default localhost)
|
||||
* `port` - used only when there is no instance in server (default 1433)
|
||||
|
||||
### Less common parameters:
|
||||
|
||||
* `keepAlive` - in seconds; 0 to disable (default is 30)
|
||||
* `failoverpartner` - host or host\instance (default is no partner).
|
||||
* `failoverport` - used only when there is no instance in failoverpartner (default 1433)
|
||||
* `packet size` - in bytes; 512 to 32767 (default is 4096)
|
||||
* Encrypted connections have a maximum packet size of 16383 bytes
|
||||
* Further information on usage: https://docs.microsoft.com/en-us/sql/database-engine/configure-windows/configure-the-network-packet-size-server-configuration-option
|
||||
* `log` - logging flags (default 0/no logging, 63 for full logging)
|
||||
* 1 log errors
|
||||
* 2 log messages
|
||||
* 4 log rows affected
|
||||
* 8 trace sql statements
|
||||
* 16 log statement parameters
|
||||
* 32 log transaction begin/end
|
||||
* `TrustServerCertificate`
|
||||
* false - Server certificate is checked. Default is false if encypt is specified.
|
||||
* true - Server certificate is not checked. Default is true if encrypt is not specified. If trust server certificate is true, driver accepts any certificate presented by the server and any host name in that certificate. In this mode, TLS is susceptible to man-in-the-middle attacks. This should be used only for testing.
|
||||
* `certificate` - The file that contains the public key certificate of the CA that signed the SQL Server certificate. The specified certificate overrides the go platform specific CA certificates.
|
||||
* `hostNameInCertificate` - Specifies the Common Name (CN) in the server certificate. Default value is the server host.
|
||||
* `ServerSPN` - The kerberos SPN (Service Principal Name) for the server. Default is MSSQLSvc/host:port.
|
||||
* `Workstation ID` - The workstation name (default is the host name)
|
||||
* `ApplicationIntent` - Can be given the value `ReadOnly` to initiate a read-only connection to an Availability Group listener.
|
||||
|
||||
### The connection string can be specified in one of three formats:
|
||||
|
||||
|
||||
1. URL: with `sqlserver` scheme. username and password appears before the host. Any instance appears as
|
||||
the first segment in the path. All other options are query parameters. Examples:
|
||||
|
||||
* `sqlserver://username:password@host/instance?param1=value¶m2=value`
|
||||
* `sqlserver://username:password@host:port?param1=value¶m2=value`
|
||||
* `sqlserver://sa@localhost/SQLExpress?database=master&connection+timeout=30` // `SQLExpress instance.
|
||||
* `sqlserver://sa:mypass@localhost?database=master&connection+timeout=30` // username=sa, password=mypass.
|
||||
* `sqlserver://sa:mypass@localhost:1234?database=master&connection+timeout=30` // port 1234 on localhost.
|
||||
* `sqlserver://sa:my%7Bpass@somehost?connection+timeout=30` // password is "my{pass"
|
||||
|
||||
A string of this format can be constructed using the `URL` type in the `net/url` package.
|
||||
|
||||
```go
|
||||
query := url.Values{}
|
||||
query.Add("app name", "MyAppName")
|
||||
|
||||
u := &url.URL{
|
||||
Scheme: "sqlserver",
|
||||
User: url.UserPassword(username, password),
|
||||
Host: fmt.Sprintf("%s:%d", hostname, port),
|
||||
// Path: instance, // if connecting to an instance instead of a port
|
||||
RawQuery: query.Encode(),
|
||||
}
|
||||
db, err := sql.Open("sqlserver", u.String())
|
||||
```
|
||||
|
||||
2. ADO: `key=value` pairs separated by `;`. Values may not contain `;`, leading and trailing whitespace is ignored.
|
||||
Examples:
|
||||
|
||||
* `server=localhost\\SQLExpress;user id=sa;database=master;app name=MyAppName`
|
||||
* `server=localhost;user id=sa;database=master;app name=MyAppName`
|
||||
|
||||
3. ODBC: Prefix with `odbc`, `key=value` pairs separated by `;`. Allow `;` by wrapping
|
||||
values in `{}`. Examples:
|
||||
|
||||
* `odbc:server=localhost\\SQLExpress;user id=sa;database=master;app name=MyAppName`
|
||||
* `odbc:server=localhost;user id=sa;database=master;app name=MyAppName`
|
||||
* `odbc:server=localhost;user id=sa;password={foo;bar}` // Value marked with `{}`, password is "foo;bar"
|
||||
* `odbc:server=localhost;user id=sa;password={foo{bar}` // Value marked with `{}`, password is "foo{bar"
|
||||
* `odbc:server=localhost;user id=sa;password={foobar }` // Value marked with `{}`, password is "foobar "
|
||||
* `odbc:server=localhost;user id=sa;password=foo{bar` // Literal `{`, password is "foo{bar"
|
||||
* `odbc:server=localhost;user id=sa;password=foo}bar` // Literal `}`, password is "foo}bar"
|
||||
* `odbc:server=localhost;user id=sa;password={foo{bar}` // Literal `{`, password is "foo{bar"
|
||||
* `odbc:server=localhost;user id=sa;password={foo}}bar}` // Escaped `} with `}}`, password is "foo}bar"
|
||||
|
||||
## Executing Stored Procedures
|
||||
|
||||
To run a stored procedure, set the query text to the procedure name:
|
||||
```go
|
||||
var account = "abc"
|
||||
_, err := db.ExecContext(ctx, "sp_RunMe",
|
||||
sql.Named("ID", 123),
|
||||
sql.Named("Account", sql.Out{Dest: &account}),
|
||||
)
|
||||
```
|
||||
|
||||
## Reading Output Parameters from a Stored Procedure with Resultset
|
||||
|
||||
To read output parameters from a stored procedure with resultset, make sure you read all the rows before reading the output parameters:
|
||||
```go
|
||||
sqltextcreate := `
|
||||
CREATE PROCEDURE spwithoutputandrows
|
||||
@bitparam BIT OUTPUT
|
||||
AS BEGIN
|
||||
SET @bitparam = 1
|
||||
SELECT 'Row 1'
|
||||
END
|
||||
`
|
||||
var bitout int64
|
||||
rows, err := db.QueryContext(ctx, "spwithoutputandrows", sql.Named("bitparam", sql.Out{Dest: &bitout}))
|
||||
var strrow string
|
||||
for rows.Next() {
|
||||
err = rows.Scan(&strrow)
|
||||
}
|
||||
fmt.Printf("bitparam is %d", bitout)
|
||||
```
|
||||
|
||||
## Caveat for local temporary tables
|
||||
|
||||
Due to protocol limitations, temporary tables will only be allocated on the connection
|
||||
as a result of executing a query with zero parameters. The following query
|
||||
will, due to the use of a parameter, execute in its own session,
|
||||
and `#mytemp` will be de-allocated right away:
|
||||
|
||||
```go
|
||||
conn, err := pool.Conn(ctx)
|
||||
defer conn.Close()
|
||||
_, err := conn.ExecContext(ctx, "select @p1 as x into #mytemp", 1)
|
||||
// at this point #mytemp is already dropped again as the session of the ExecContext is over
|
||||
```
|
||||
|
||||
To work around this, always explicitly create the local temporary
|
||||
table in a query without any parameters. As a special case, the driver
|
||||
will then be able to execute the query directly on the
|
||||
connection-scoped session. The following example works:
|
||||
|
||||
```go
|
||||
conn, err := pool.Conn(ctx)
|
||||
|
||||
// Set us up so that temp table is always cleaned up, since conn.Close()
|
||||
// merely returns conn to pool, rather than actually closing the connection.
|
||||
defer func() {
|
||||
_, _ = conn.ExecContext(ctx, "drop table #mytemp") // always clean up
|
||||
conn.Close() // merely returns conn to pool
|
||||
}()
|
||||
|
||||
|
||||
// Since we not pass any parameters below, the query will execute on the scope of
|
||||
// the connection and succeed in creating the table.
|
||||
_, err := conn.ExecContext(ctx, "create table #mytemp ( x int )")
|
||||
|
||||
// #mytemp is now available even if you pass parameters
|
||||
_, err := conn.ExecContext(ctx, "insert into #mytemp (x) values (@p1)", 1)
|
||||
|
||||
```
|
||||
|
||||
## Return Status
|
||||
|
||||
To get the procedure return status, pass into the parameters a
|
||||
`*mssql.ReturnStatus`. For example:
|
||||
```
|
||||
var rs mssql.ReturnStatus
|
||||
_, err := db.ExecContext(ctx, "theproc", &rs)
|
||||
log.Printf("status=%d", rs)
|
||||
```
|
||||
|
||||
## Parameters
|
||||
|
||||
The `sqlserver` driver uses normal MS SQL Server syntax and expects parameters in
|
||||
the sql query to be in the form of either `@Name` or `@p1` to `@pN` (ordinal position).
|
||||
|
||||
```go
|
||||
db.QueryContext(ctx, `select * from t where ID = @ID and Name = @p2;`, sql.Named("ID", 6), "Bob")
|
||||
```
|
||||
|
||||
### Parameter Types
|
||||
|
||||
To pass specific types to the query parameters, say `varchar` or `date` types,
|
||||
you must convert the types to the type before passing in. The following types
|
||||
are supported:
|
||||
|
||||
* string -> nvarchar
|
||||
* mssql.VarChar -> varchar
|
||||
* time.Time -> datetimeoffset or datetime (TDS version dependent)
|
||||
* mssql.DateTime1 -> datetime
|
||||
* mssql.DateTimeOffset -> datetimeoffset
|
||||
* "cloud.google.com/go/civil".Date -> date
|
||||
* "cloud.google.com/go/civil".DateTime -> datetime2
|
||||
* "cloud.google.com/go/civil".Time -> time
|
||||
* mssql.TVP -> Table Value Parameter (TDS version dependent)
|
||||
|
||||
## Important Notes
|
||||
|
||||
* [LastInsertId](https://golang.org/pkg/database/sql/#Result.LastInsertId) should
|
||||
not be used with this driver (or SQL Server) due to how the TDS protocol
|
||||
works. Please use the [OUTPUT Clause](https://docs.microsoft.com/en-us/sql/t-sql/queries/output-clause-transact-sql)
|
||||
or add a `select ID = convert(bigint, SCOPE_IDENTITY());` to the end of your
|
||||
query (ref [SCOPE_IDENTITY](https://docs.microsoft.com/en-us/sql/t-sql/functions/scope-identity-transact-sql)).
|
||||
This will ensure you are getting the correct ID and will prevent a network round trip.
|
||||
* [NewConnector](https://godoc.org/github.com/denisenkom/go-mssqldb#NewConnector)
|
||||
may be used with [OpenDB](https://golang.org/pkg/database/sql/#OpenDB).
|
||||
* [Connector.SessionInitSQL](https://godoc.org/github.com/denisenkom/go-mssqldb#Connector.SessionInitSQL)
|
||||
may be set to set any driver specific session settings after the session
|
||||
has been reset. If empty the session will still be reset but use the database
|
||||
defaults in Go1.10+.
|
||||
|
||||
## Features
|
||||
|
||||
* Can be used with SQL Server 2005 or newer
|
||||
* Can be used with Microsoft Azure SQL Database
|
||||
* Can be used on all go supported platforms (e.g. Linux, Mac OS X and Windows)
|
||||
* Supports new date/time types: date, time, datetime2, datetimeoffset
|
||||
* Supports string parameters longer than 8000 characters
|
||||
* Supports encryption using SSL/TLS
|
||||
* Supports SQL Server and Windows Authentication
|
||||
* Supports Single-Sign-On on Windows
|
||||
* Supports connections to AlwaysOn Availability Group listeners, including re-direction to read-only replicas.
|
||||
* Supports query notifications
|
||||
|
||||
## Tests
|
||||
|
||||
`go test` is used for testing. A running instance of MSSQL server is required.
|
||||
Environment variables are used to pass login information.
|
||||
|
||||
Example:
|
||||
|
||||
env SQLSERVER_DSN=sqlserver://user:pass@hostname/instance?database=test1 go test
|
||||
|
||||
## Deprecated
|
||||
|
||||
These features still exist in the driver, but they are are deprecated.
|
||||
|
||||
### Query Parameter Token Replace (driver "mssql")
|
||||
|
||||
If you use the driver name "mssql" (rather then "sqlserver") the SQL text
|
||||
will be loosly parsed and an attempt to extract identifiers using one of
|
||||
|
||||
* ?
|
||||
* ?nnn
|
||||
* :nnn
|
||||
* $nnn
|
||||
|
||||
will be used. This is not recommended with SQL Server.
|
||||
There is at least one existing `won't fix` issue with the query parsing.
|
||||
|
||||
Use the native "@Name" parameters instead with the "sqlserver" driver name.
|
||||
|
||||
## Known Issues
|
||||
|
||||
* SQL Server 2008 and 2008 R2 engine cannot handle login records when SSL encryption is not disabled.
|
||||
To fix SQL Server 2008 R2 issue, install SQL Server 2008 R2 Service Pack 2.
|
||||
To fix SQL Server 2008 issue, install Microsoft SQL Server 2008 Service Pack 3 and Cumulative update package 3 for SQL Server 2008 SP3.
|
||||
More information: http://support.microsoft.com/kb/2653857
|
|
@ -1,48 +0,0 @@
|
|||
version: 1.0.{build}
|
||||
|
||||
os: Windows Server 2012 R2
|
||||
|
||||
clone_folder: c:\gopath\src\github.com\denisenkom\go-mssqldb
|
||||
|
||||
environment:
|
||||
GOPATH: c:\gopath
|
||||
HOST: localhost
|
||||
SQLUSER: sa
|
||||
SQLPASSWORD: Password12!
|
||||
DATABASE: test
|
||||
GOVERSION: 110
|
||||
matrix:
|
||||
- GOVERSION: 18
|
||||
SQLINSTANCE: SQL2016
|
||||
- GOVERSION: 19
|
||||
SQLINSTANCE: SQL2016
|
||||
- GOVERSION: 110
|
||||
SQLINSTANCE: SQL2016
|
||||
- SQLINSTANCE: SQL2014
|
||||
- SQLINSTANCE: SQL2012SP1
|
||||
- SQLINSTANCE: SQL2008R2SP2
|
||||
|
||||
install:
|
||||
- set GOROOT=c:\go%GOVERSION%
|
||||
- set PATH=%GOPATH%\bin;%GOROOT%\bin;%PATH%
|
||||
- go version
|
||||
- go env
|
||||
- go get -u cloud.google.com/go/civil
|
||||
|
||||
build_script:
|
||||
- go build
|
||||
|
||||
before_test:
|
||||
# setup SQL Server
|
||||
- ps: |
|
||||
$instanceName = $env:SQLINSTANCE
|
||||
Start-Service "MSSQL`$$instanceName"
|
||||
Start-Service "SQLBrowser"
|
||||
- sqlcmd -S "(local)\%SQLINSTANCE%" -Q "Use [master]; CREATE DATABASE test;"
|
||||
- sqlcmd -S "(local)\%SQLINSTANCE%" -h -1 -Q "set nocount on; Select @@version"
|
||||
- pip install codecov
|
||||
|
||||
|
||||
test_script:
|
||||
- go test -race -cpu 4 -coverprofile=coverage.txt -covermode=atomic
|
||||
- codecov -f coverage.txt
|
|
@ -1,258 +0,0 @@
|
|||
package mssql
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"io"
|
||||
)
|
||||
|
||||
type packetType uint8
|
||||
|
||||
type header struct {
|
||||
PacketType packetType
|
||||
Status uint8
|
||||
Size uint16
|
||||
Spid uint16
|
||||
PacketNo uint8
|
||||
Pad uint8
|
||||
}
|
||||
|
||||
// tdsBuffer reads and writes TDS packets of data to the transport.
|
||||
// The write and read buffers are separate to make sending attn signals
|
||||
// possible without locks. Currently attn signals are only sent during
|
||||
// reads, not writes.
|
||||
type tdsBuffer struct {
|
||||
transport io.ReadWriteCloser
|
||||
|
||||
packetSize int
|
||||
|
||||
// Write fields.
|
||||
wbuf []byte
|
||||
wpos int
|
||||
wPacketSeq byte
|
||||
wPacketType packetType
|
||||
|
||||
// Read fields.
|
||||
rbuf []byte
|
||||
rpos int
|
||||
rsize int
|
||||
final bool
|
||||
rPacketType packetType
|
||||
|
||||
// afterFirst is assigned to right after tdsBuffer is created and
|
||||
// before the first use. It is executed after the first packet is
|
||||
// written and then removed.
|
||||
afterFirst func()
|
||||
}
|
||||
|
||||
func newTdsBuffer(bufsize uint16, transport io.ReadWriteCloser) *tdsBuffer {
|
||||
return &tdsBuffer{
|
||||
packetSize: int(bufsize),
|
||||
wbuf: make([]byte, 1<<16),
|
||||
rbuf: make([]byte, 1<<16),
|
||||
rpos: 8,
|
||||
transport: transport,
|
||||
}
|
||||
}
|
||||
|
||||
func (rw *tdsBuffer) ResizeBuffer(packetSize int) {
|
||||
rw.packetSize = packetSize
|
||||
}
|
||||
|
||||
func (w *tdsBuffer) PackageSize() int {
|
||||
return w.packetSize
|
||||
}
|
||||
|
||||
func (w *tdsBuffer) flush() (err error) {
|
||||
// Write packet size.
|
||||
w.wbuf[0] = byte(w.wPacketType)
|
||||
binary.BigEndian.PutUint16(w.wbuf[2:], uint16(w.wpos))
|
||||
w.wbuf[6] = w.wPacketSeq
|
||||
|
||||
// Write packet into underlying transport.
|
||||
if _, err = w.transport.Write(w.wbuf[:w.wpos]); err != nil {
|
||||
return err
|
||||
}
|
||||
// It is possible to create a whole new buffer after a flush.
|
||||
// Useful for debugging. Normally reuse the buffer.
|
||||
// w.wbuf = make([]byte, 1<<16)
|
||||
|
||||
// Execute afterFirst hook if it is set.
|
||||
if w.afterFirst != nil {
|
||||
w.afterFirst()
|
||||
w.afterFirst = nil
|
||||
}
|
||||
|
||||
w.wpos = 8
|
||||
w.wPacketSeq++
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *tdsBuffer) Write(p []byte) (total int, err error) {
|
||||
for {
|
||||
copied := copy(w.wbuf[w.wpos:w.packetSize], p)
|
||||
w.wpos += copied
|
||||
total += copied
|
||||
if copied == len(p) {
|
||||
return
|
||||
}
|
||||
if err = w.flush(); err != nil {
|
||||
return
|
||||
}
|
||||
p = p[copied:]
|
||||
}
|
||||
}
|
||||
|
||||
func (w *tdsBuffer) WriteByte(b byte) error {
|
||||
if int(w.wpos) == len(w.wbuf) || w.wpos == w.packetSize {
|
||||
if err := w.flush(); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
w.wbuf[w.wpos] = b
|
||||
w.wpos += 1
|
||||
return nil
|
||||
}
|
||||
|
||||
func (w *tdsBuffer) BeginPacket(packetType packetType, resetSession bool) {
|
||||
status := byte(0)
|
||||
if resetSession {
|
||||
switch packetType {
|
||||
// Reset session can only be set on the following packet types.
|
||||
case packSQLBatch, packRPCRequest, packTransMgrReq:
|
||||
status = 0x8
|
||||
}
|
||||
}
|
||||
w.wbuf[1] = status // Packet is incomplete. This byte is set again in FinishPacket.
|
||||
w.wpos = 8
|
||||
w.wPacketSeq = 1
|
||||
w.wPacketType = packetType
|
||||
}
|
||||
|
||||
func (w *tdsBuffer) FinishPacket() error {
|
||||
w.wbuf[1] |= 1 // Mark this as the last packet in the message.
|
||||
return w.flush()
|
||||
}
|
||||
|
||||
var headerSize = binary.Size(header{})
|
||||
|
||||
func (r *tdsBuffer) readNextPacket() error {
|
||||
h := header{}
|
||||
var err error
|
||||
err = binary.Read(r.transport, binary.BigEndian, &h)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
if int(h.Size) > r.packetSize {
|
||||
return errors.New("Invalid packet size, it is longer than buffer size")
|
||||
}
|
||||
if headerSize > int(h.Size) {
|
||||
return errors.New("Invalid packet size, it is shorter than header size")
|
||||
}
|
||||
_, err = io.ReadFull(r.transport, r.rbuf[headerSize:h.Size])
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
r.rpos = headerSize
|
||||
r.rsize = int(h.Size)
|
||||
r.final = h.Status != 0
|
||||
r.rPacketType = h.PacketType
|
||||
return nil
|
||||
}
|
||||
|
||||
func (r *tdsBuffer) BeginRead() (packetType, error) {
|
||||
err := r.readNextPacket()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
return r.rPacketType, nil
|
||||
}
|
||||
|
||||
func (r *tdsBuffer) ReadByte() (res byte, err error) {
|
||||
if r.rpos == r.rsize {
|
||||
if r.final {
|
||||
return 0, io.EOF
|
||||
}
|
||||
err = r.readNextPacket()
|
||||
if err != nil {
|
||||
return 0, err
|
||||
}
|
||||
}
|
||||
res = r.rbuf[r.rpos]
|
||||
r.rpos++
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (r *tdsBuffer) byte() byte {
|
||||
b, err := r.ReadByte()
|
||||
if err != nil {
|
||||
badStreamPanic(err)
|
||||
}
|
||||
return b
|
||||
}
|
||||
|
||||
func (r *tdsBuffer) ReadFull(buf []byte) {
|
||||
_, err := io.ReadFull(r, buf[:])
|
||||
if err != nil {
|
||||
badStreamPanic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (r *tdsBuffer) uint64() uint64 {
|
||||
var buf [8]byte
|
||||
r.ReadFull(buf[:])
|
||||
return binary.LittleEndian.Uint64(buf[:])
|
||||
}
|
||||
|
||||
func (r *tdsBuffer) int32() int32 {
|
||||
return int32(r.uint32())
|
||||
}
|
||||
|
||||
func (r *tdsBuffer) uint32() uint32 {
|
||||
var buf [4]byte
|
||||
r.ReadFull(buf[:])
|
||||
return binary.LittleEndian.Uint32(buf[:])
|
||||
}
|
||||
|
||||
func (r *tdsBuffer) uint16() uint16 {
|
||||
var buf [2]byte
|
||||
r.ReadFull(buf[:])
|
||||
return binary.LittleEndian.Uint16(buf[:])
|
||||
}
|
||||
|
||||
func (r *tdsBuffer) BVarChar() string {
|
||||
l := int(r.byte())
|
||||
return r.readUcs2(l)
|
||||
}
|
||||
|
||||
func (r *tdsBuffer) UsVarChar() string {
|
||||
l := int(r.uint16())
|
||||
return r.readUcs2(l)
|
||||
}
|
||||
|
||||
func (r *tdsBuffer) readUcs2(numchars int) string {
|
||||
b := make([]byte, numchars*2)
|
||||
r.ReadFull(b)
|
||||
res, err := ucs22str(b)
|
||||
if err != nil {
|
||||
badStreamPanic(err)
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
func (r *tdsBuffer) Read(buf []byte) (copied int, err error) {
|
||||
copied = 0
|
||||
err = nil
|
||||
if r.rpos == r.rsize {
|
||||
if r.final {
|
||||
return 0, io.EOF
|
||||
}
|
||||
err = r.readNextPacket()
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
copied = copy(buf, r.rbuf[r.rpos:r.rsize])
|
||||
r.rpos += copied
|
||||
return
|
||||
}
|
|
@ -1,554 +0,0 @@
|
|||
package mssql
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"context"
|
||||
"encoding/binary"
|
||||
"fmt"
|
||||
"math"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
)
|
||||
|
||||
type Bulk struct {
|
||||
// ctx is used only for AddRow and Done methods.
|
||||
// This could be removed if AddRow and Done accepted
|
||||
// a ctx field as well, which is available with the
|
||||
// database/sql call.
|
||||
ctx context.Context
|
||||
|
||||
cn *Conn
|
||||
metadata []columnStruct
|
||||
bulkColumns []columnStruct
|
||||
columnsName []string
|
||||
tablename string
|
||||
numRows int
|
||||
|
||||
headerSent bool
|
||||
Options BulkOptions
|
||||
Debug bool
|
||||
}
|
||||
type BulkOptions struct {
|
||||
CheckConstraints bool
|
||||
FireTriggers bool
|
||||
KeepNulls bool
|
||||
KilobytesPerBatch int
|
||||
RowsPerBatch int
|
||||
Order []string
|
||||
Tablock bool
|
||||
}
|
||||
|
||||
type DataValue interface{}
|
||||
|
||||
func (cn *Conn) CreateBulk(table string, columns []string) (_ *Bulk) {
|
||||
b := Bulk{ctx: context.Background(), cn: cn, tablename: table, headerSent: false, columnsName: columns}
|
||||
b.Debug = false
|
||||
return &b
|
||||
}
|
||||
|
||||
func (cn *Conn) CreateBulkContext(ctx context.Context, table string, columns []string) (_ *Bulk) {
|
||||
b := Bulk{ctx: ctx, cn: cn, tablename: table, headerSent: false, columnsName: columns}
|
||||
b.Debug = false
|
||||
return &b
|
||||
}
|
||||
|
||||
func (b *Bulk) sendBulkCommand(ctx context.Context) (err error) {
|
||||
//get table columns info
|
||||
err = b.getMetadata(ctx)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
//match the columns
|
||||
for _, colname := range b.columnsName {
|
||||
var bulkCol *columnStruct
|
||||
|
||||
for _, m := range b.metadata {
|
||||
if m.ColName == colname {
|
||||
bulkCol = &m
|
||||
break
|
||||
}
|
||||
}
|
||||
if bulkCol != nil {
|
||||
|
||||
if bulkCol.ti.TypeId == typeUdt {
|
||||
//send udt as binary
|
||||
bulkCol.ti.TypeId = typeBigVarBin
|
||||
}
|
||||
b.bulkColumns = append(b.bulkColumns, *bulkCol)
|
||||
b.dlogf("Adding column %s %s %#x", colname, bulkCol.ColName, bulkCol.ti.TypeId)
|
||||
} else {
|
||||
return fmt.Errorf("Column %s does not exist in destination table %s", colname, b.tablename)
|
||||
}
|
||||
}
|
||||
|
||||
//create the bulk command
|
||||
|
||||
//columns definitions
|
||||
var col_defs bytes.Buffer
|
||||
for i, col := range b.bulkColumns {
|
||||
if i != 0 {
|
||||
col_defs.WriteString(", ")
|
||||
}
|
||||
col_defs.WriteString("[" + col.ColName + "] " + makeDecl(col.ti))
|
||||
}
|
||||
|
||||
//options
|
||||
var with_opts []string
|
||||
|
||||
if b.Options.CheckConstraints {
|
||||
with_opts = append(with_opts, "CHECK_CONSTRAINTS")
|
||||
}
|
||||
if b.Options.FireTriggers {
|
||||
with_opts = append(with_opts, "FIRE_TRIGGERS")
|
||||
}
|
||||
if b.Options.KeepNulls {
|
||||
with_opts = append(with_opts, "KEEP_NULLS")
|
||||
}
|
||||
if b.Options.KilobytesPerBatch > 0 {
|
||||
with_opts = append(with_opts, fmt.Sprintf("KILOBYTES_PER_BATCH = %d", b.Options.KilobytesPerBatch))
|
||||
}
|
||||
if b.Options.RowsPerBatch > 0 {
|
||||
with_opts = append(with_opts, fmt.Sprintf("ROWS_PER_BATCH = %d", b.Options.RowsPerBatch))
|
||||
}
|
||||
if len(b.Options.Order) > 0 {
|
||||
with_opts = append(with_opts, fmt.Sprintf("ORDER(%s)", strings.Join(b.Options.Order, ",")))
|
||||
}
|
||||
if b.Options.Tablock {
|
||||
with_opts = append(with_opts, "TABLOCK")
|
||||
}
|
||||
var with_part string
|
||||
if len(with_opts) > 0 {
|
||||
with_part = fmt.Sprintf("WITH (%s)", strings.Join(with_opts, ","))
|
||||
}
|
||||
|
||||
query := fmt.Sprintf("INSERT BULK %s (%s) %s", b.tablename, col_defs.String(), with_part)
|
||||
|
||||
stmt, err := b.cn.PrepareContext(ctx, query)
|
||||
if err != nil {
|
||||
return fmt.Errorf("Prepare failed: %s", err.Error())
|
||||
}
|
||||
b.dlogf(query)
|
||||
|
||||
_, err = stmt.(*Stmt).ExecContext(ctx, nil)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
b.headerSent = true
|
||||
|
||||
var buf = b.cn.sess.buf
|
||||
buf.BeginPacket(packBulkLoadBCP, false)
|
||||
|
||||
// Send the columns metadata.
|
||||
columnMetadata := b.createColMetadata()
|
||||
_, err = buf.Write(columnMetadata)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
// AddRow immediately writes the row to the destination table.
|
||||
// The arguments are the row values in the order they were specified.
|
||||
func (b *Bulk) AddRow(row []interface{}) (err error) {
|
||||
if !b.headerSent {
|
||||
err = b.sendBulkCommand(b.ctx)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
}
|
||||
|
||||
if len(row) != len(b.bulkColumns) {
|
||||
return fmt.Errorf("Row does not have the same number of columns than the destination table %d %d",
|
||||
len(row), len(b.bulkColumns))
|
||||
}
|
||||
|
||||
bytes, err := b.makeRowData(row)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
_, err = b.cn.sess.buf.Write(bytes)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
b.numRows = b.numRows + 1
|
||||
return
|
||||
}
|
||||
|
||||
func (b *Bulk) makeRowData(row []interface{}) ([]byte, error) {
|
||||
buf := new(bytes.Buffer)
|
||||
buf.WriteByte(byte(tokenRow))
|
||||
|
||||
var logcol bytes.Buffer
|
||||
for i, col := range b.bulkColumns {
|
||||
|
||||
if b.Debug {
|
||||
logcol.WriteString(fmt.Sprintf(" col[%d]='%v' ", i, row[i]))
|
||||
}
|
||||
param, err := b.makeParam(row[i], col)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("bulkcopy: %s", err.Error())
|
||||
}
|
||||
|
||||
if col.ti.Writer == nil {
|
||||
return nil, fmt.Errorf("no writer for column: %s, TypeId: %#x",
|
||||
col.ColName, col.ti.TypeId)
|
||||
}
|
||||
err = col.ti.Writer(buf, param.ti, param.buffer)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("bulkcopy: %s", err.Error())
|
||||
}
|
||||
}
|
||||
|
||||
b.dlogf("row[%d] %s\n", b.numRows, logcol.String())
|
||||
|
||||
return buf.Bytes(), nil
|
||||
}
|
||||
|
||||
func (b *Bulk) Done() (rowcount int64, err error) {
|
||||
if b.headerSent == false {
|
||||
//no rows had been sent
|
||||
return 0, nil
|
||||
}
|
||||
var buf = b.cn.sess.buf
|
||||
buf.WriteByte(byte(tokenDone))
|
||||
|
||||
binary.Write(buf, binary.LittleEndian, uint16(doneFinal))
|
||||
binary.Write(buf, binary.LittleEndian, uint16(0)) // curcmd
|
||||
|
||||
if b.cn.sess.loginAck.TDSVersion >= verTDS72 {
|
||||
binary.Write(buf, binary.LittleEndian, uint64(0)) //rowcount 0
|
||||
} else {
|
||||
binary.Write(buf, binary.LittleEndian, uint32(0)) //rowcount 0
|
||||
}
|
||||
|
||||
buf.FinishPacket()
|
||||
|
||||
tokchan := make(chan tokenStruct, 5)
|
||||
go processResponse(b.ctx, b.cn.sess, tokchan, nil)
|
||||
|
||||
var rowCount int64
|
||||
for token := range tokchan {
|
||||
switch token := token.(type) {
|
||||
case doneStruct:
|
||||
if token.Status&doneCount != 0 {
|
||||
rowCount = int64(token.RowCount)
|
||||
}
|
||||
if token.isError() {
|
||||
return 0, token.getError()
|
||||
}
|
||||
case error:
|
||||
return 0, b.cn.checkBadConn(token)
|
||||
}
|
||||
}
|
||||
return rowCount, nil
|
||||
}
|
||||
|
||||
func (b *Bulk) createColMetadata() []byte {
|
||||
buf := new(bytes.Buffer)
|
||||
buf.WriteByte(byte(tokenColMetadata)) // token
|
||||
binary.Write(buf, binary.LittleEndian, uint16(len(b.bulkColumns))) // column count
|
||||
|
||||
for i, col := range b.bulkColumns {
|
||||
|
||||
if b.cn.sess.loginAck.TDSVersion >= verTDS72 {
|
||||
binary.Write(buf, binary.LittleEndian, uint32(col.UserType)) // usertype, always 0?
|
||||
} else {
|
||||
binary.Write(buf, binary.LittleEndian, uint16(col.UserType))
|
||||
}
|
||||
binary.Write(buf, binary.LittleEndian, uint16(col.Flags))
|
||||
|
||||
writeTypeInfo(buf, &b.bulkColumns[i].ti)
|
||||
|
||||
if col.ti.TypeId == typeNText ||
|
||||
col.ti.TypeId == typeText ||
|
||||
col.ti.TypeId == typeImage {
|
||||
|
||||
tablename_ucs2 := str2ucs2(b.tablename)
|
||||
binary.Write(buf, binary.LittleEndian, uint16(len(tablename_ucs2)/2))
|
||||
buf.Write(tablename_ucs2)
|
||||
}
|
||||
colname_ucs2 := str2ucs2(col.ColName)
|
||||
buf.WriteByte(uint8(len(colname_ucs2) / 2))
|
||||
buf.Write(colname_ucs2)
|
||||
}
|
||||
|
||||
return buf.Bytes()
|
||||
}
|
||||
|
||||
func (b *Bulk) getMetadata(ctx context.Context) (err error) {
|
||||
stmt, err := b.cn.prepareContext(ctx, "SET FMTONLY ON")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
_, err = stmt.ExecContext(ctx, nil)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
// Get columns info.
|
||||
stmt, err = b.cn.prepareContext(ctx, fmt.Sprintf("select * from %s SET FMTONLY OFF", b.tablename))
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
rows, err := stmt.QueryContext(ctx, nil)
|
||||
if err != nil {
|
||||
return fmt.Errorf("get columns info failed: %v", err)
|
||||
}
|
||||
b.metadata = rows.(*Rows).cols
|
||||
|
||||
if b.Debug {
|
||||
for _, col := range b.metadata {
|
||||
b.dlogf("col: %s typeId: %#x size: %d scale: %d prec: %d flags: %d lcid: %#x\n",
|
||||
col.ColName, col.ti.TypeId, col.ti.Size, col.ti.Scale, col.ti.Prec,
|
||||
col.Flags, col.ti.Collation.LcidAndFlags)
|
||||
}
|
||||
}
|
||||
|
||||
return rows.Close()
|
||||
}
|
||||
|
||||
func (b *Bulk) makeParam(val DataValue, col columnStruct) (res param, err error) {
|
||||
res.ti.Size = col.ti.Size
|
||||
res.ti.TypeId = col.ti.TypeId
|
||||
|
||||
if val == nil {
|
||||
res.ti.Size = 0
|
||||
return
|
||||
}
|
||||
|
||||
switch col.ti.TypeId {
|
||||
|
||||
case typeInt1, typeInt2, typeInt4, typeInt8, typeIntN:
|
||||
var intvalue int64
|
||||
|
||||
switch val := val.(type) {
|
||||
case int:
|
||||
intvalue = int64(val)
|
||||
case int32:
|
||||
intvalue = int64(val)
|
||||
case int64:
|
||||
intvalue = val
|
||||
default:
|
||||
err = fmt.Errorf("mssql: invalid type for int column")
|
||||
return
|
||||
}
|
||||
|
||||
res.buffer = make([]byte, res.ti.Size)
|
||||
if col.ti.Size == 1 {
|
||||
res.buffer[0] = byte(intvalue)
|
||||
} else if col.ti.Size == 2 {
|
||||
binary.LittleEndian.PutUint16(res.buffer, uint16(intvalue))
|
||||
} else if col.ti.Size == 4 {
|
||||
binary.LittleEndian.PutUint32(res.buffer, uint32(intvalue))
|
||||
} else if col.ti.Size == 8 {
|
||||
binary.LittleEndian.PutUint64(res.buffer, uint64(intvalue))
|
||||
}
|
||||
case typeFlt4, typeFlt8, typeFltN:
|
||||
var floatvalue float64
|
||||
|
||||
switch val := val.(type) {
|
||||
case float32:
|
||||
floatvalue = float64(val)
|
||||
case float64:
|
||||
floatvalue = val
|
||||
case int:
|
||||
floatvalue = float64(val)
|
||||
case int64:
|
||||
floatvalue = float64(val)
|
||||
default:
|
||||
err = fmt.Errorf("mssql: invalid type for float column: %s", val)
|
||||
return
|
||||
}
|
||||
|
||||
if col.ti.Size == 4 {
|
||||
res.buffer = make([]byte, 4)
|
||||
binary.LittleEndian.PutUint32(res.buffer, math.Float32bits(float32(floatvalue)))
|
||||
} else if col.ti.Size == 8 {
|
||||
res.buffer = make([]byte, 8)
|
||||
binary.LittleEndian.PutUint64(res.buffer, math.Float64bits(floatvalue))
|
||||
}
|
||||
case typeNVarChar, typeNText, typeNChar:
|
||||
|
||||
switch val := val.(type) {
|
||||
case string:
|
||||
res.buffer = str2ucs2(val)
|
||||
case []byte:
|
||||
res.buffer = val
|
||||
default:
|
||||
err = fmt.Errorf("mssql: invalid type for nvarchar column: %s", val)
|
||||
return
|
||||
}
|
||||
res.ti.Size = len(res.buffer)
|
||||
|
||||
case typeVarChar, typeBigVarChar, typeText, typeChar, typeBigChar:
|
||||
switch val := val.(type) {
|
||||
case string:
|
||||
res.buffer = []byte(val)
|
||||
case []byte:
|
||||
res.buffer = val
|
||||
default:
|
||||
err = fmt.Errorf("mssql: invalid type for varchar column: %s", val)
|
||||
return
|
||||
}
|
||||
res.ti.Size = len(res.buffer)
|
||||
|
||||
case typeBit, typeBitN:
|
||||
if reflect.TypeOf(val).Kind() != reflect.Bool {
|
||||
err = fmt.Errorf("mssql: invalid type for bit column: %s", val)
|
||||
return
|
||||
}
|
||||
res.ti.TypeId = typeBitN
|
||||
res.ti.Size = 1
|
||||
res.buffer = make([]byte, 1)
|
||||
if val.(bool) {
|
||||
res.buffer[0] = 1
|
||||
}
|
||||
case typeDateTime2N:
|
||||
switch val := val.(type) {
|
||||
case time.Time:
|
||||
res.buffer = encodeDateTime2(val, int(col.ti.Scale))
|
||||
res.ti.Size = len(res.buffer)
|
||||
default:
|
||||
err = fmt.Errorf("mssql: invalid type for datetime2 column: %s", val)
|
||||
return
|
||||
}
|
||||
case typeDateTimeOffsetN:
|
||||
switch val := val.(type) {
|
||||
case time.Time:
|
||||
res.buffer = encodeDateTimeOffset(val, int(res.ti.Scale))
|
||||
res.ti.Size = len(res.buffer)
|
||||
|
||||
default:
|
||||
err = fmt.Errorf("mssql: invalid type for datetimeoffset column: %s", val)
|
||||
return
|
||||
}
|
||||
case typeDateN:
|
||||
switch val := val.(type) {
|
||||
case time.Time:
|
||||
res.buffer = encodeDate(val)
|
||||
res.ti.Size = len(res.buffer)
|
||||
default:
|
||||
err = fmt.Errorf("mssql: invalid type for date column: %s", val)
|
||||
return
|
||||
}
|
||||
case typeDateTime, typeDateTimeN, typeDateTim4:
|
||||
switch val := val.(type) {
|
||||
case time.Time:
|
||||
if col.ti.Size == 4 {
|
||||
res.buffer = encodeDateTim4(val)
|
||||
res.ti.Size = len(res.buffer)
|
||||
} else if col.ti.Size == 8 {
|
||||
res.buffer = encodeDateTime(val)
|
||||
res.ti.Size = len(res.buffer)
|
||||
} else {
|
||||
err = fmt.Errorf("mssql: invalid size of column")
|
||||
}
|
||||
|
||||
default:
|
||||
err = fmt.Errorf("mssql: invalid type for datetime column: %s", val)
|
||||
}
|
||||
|
||||
// case typeMoney, typeMoney4, typeMoneyN:
|
||||
case typeDecimal, typeDecimalN, typeNumeric, typeNumericN:
|
||||
var value float64
|
||||
switch v := val.(type) {
|
||||
case int:
|
||||
value = float64(v)
|
||||
case int8:
|
||||
value = float64(v)
|
||||
case int16:
|
||||
value = float64(v)
|
||||
case int32:
|
||||
value = float64(v)
|
||||
case int64:
|
||||
value = float64(v)
|
||||
case float32:
|
||||
value = float64(v)
|
||||
case float64:
|
||||
value = v
|
||||
case string:
|
||||
if value, err = strconv.ParseFloat(v, 64); err != nil {
|
||||
return res, fmt.Errorf("bulk: unable to convert string to float: %v", err)
|
||||
}
|
||||
default:
|
||||
return res, fmt.Errorf("unknown value for decimal: %#v", v)
|
||||
}
|
||||
|
||||
perc := col.ti.Prec
|
||||
scale := col.ti.Scale
|
||||
var dec Decimal
|
||||
dec, err = Float64ToDecimalScale(value, scale)
|
||||
if err != nil {
|
||||
return res, err
|
||||
}
|
||||
dec.prec = perc
|
||||
|
||||
var length byte
|
||||
switch {
|
||||
case perc <= 9:
|
||||
length = 4
|
||||
case perc <= 19:
|
||||
length = 8
|
||||
case perc <= 28:
|
||||
length = 12
|
||||
default:
|
||||
length = 16
|
||||
}
|
||||
|
||||
buf := make([]byte, length+1)
|
||||
// first byte length written by typeInfo.writer
|
||||
res.ti.Size = int(length) + 1
|
||||
// second byte sign
|
||||
if value < 0 {
|
||||
buf[0] = 0
|
||||
} else {
|
||||
buf[0] = 1
|
||||
}
|
||||
|
||||
ub := dec.UnscaledBytes()
|
||||
l := len(ub)
|
||||
if l > int(length) {
|
||||
err = fmt.Errorf("decimal out of range: %s", dec)
|
||||
return res, err
|
||||
}
|
||||
// reverse the bytes
|
||||
for i, j := 1, l-1; j >= 0; i, j = i+1, j-1 {
|
||||
buf[i] = ub[j]
|
||||
}
|
||||
res.buffer = buf
|
||||
case typeBigVarBin, typeBigBinary:
|
||||
switch val := val.(type) {
|
||||
case []byte:
|
||||
res.ti.Size = len(val)
|
||||
res.buffer = val
|
||||
default:
|
||||
err = fmt.Errorf("mssql: invalid type for Binary column: %s", val)
|
||||
return
|
||||
}
|
||||
case typeGuid:
|
||||
switch val := val.(type) {
|
||||
case []byte:
|
||||
res.ti.Size = len(val)
|
||||
res.buffer = val
|
||||
default:
|
||||
err = fmt.Errorf("mssql: invalid type for Guid column: %s", val)
|
||||
return
|
||||
}
|
||||
|
||||
default:
|
||||
err = fmt.Errorf("mssql: type %x not implemented", col.ti.TypeId)
|
||||
}
|
||||
return
|
||||
|
||||
}
|
||||
|
||||
func (b *Bulk) dlogf(format string, v ...interface{}) {
|
||||
if b.Debug {
|
||||
b.cn.sess.log.Printf(format, v...)
|
||||
}
|
||||
}
|
|
@ -1,93 +0,0 @@
|
|||
package mssql
|
||||
|
||||
import (
|
||||
"context"
|
||||
"database/sql/driver"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
)
|
||||
|
||||
type copyin struct {
|
||||
cn *Conn
|
||||
bulkcopy *Bulk
|
||||
closed bool
|
||||
}
|
||||
|
||||
type serializableBulkConfig struct {
|
||||
TableName string
|
||||
ColumnsName []string
|
||||
Options BulkOptions
|
||||
}
|
||||
|
||||
func (d *Driver) OpenConnection(dsn string) (*Conn, error) {
|
||||
return d.open(context.Background(), dsn)
|
||||
}
|
||||
|
||||
func (c *Conn) prepareCopyIn(ctx context.Context, query string) (_ driver.Stmt, err error) {
|
||||
config_json := query[11:]
|
||||
|
||||
bulkconfig := serializableBulkConfig{}
|
||||
err = json.Unmarshal([]byte(config_json), &bulkconfig)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
bulkcopy := c.CreateBulkContext(ctx, bulkconfig.TableName, bulkconfig.ColumnsName)
|
||||
bulkcopy.Options = bulkconfig.Options
|
||||
|
||||
ci := ©in{
|
||||
cn: c,
|
||||
bulkcopy: bulkcopy,
|
||||
}
|
||||
|
||||
return ci, nil
|
||||
}
|
||||
|
||||
func CopyIn(table string, options BulkOptions, columns ...string) string {
|
||||
bulkconfig := &serializableBulkConfig{TableName: table, Options: options, ColumnsName: columns}
|
||||
|
||||
config_json, err := json.Marshal(bulkconfig)
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
stmt := "INSERTBULK " + string(config_json)
|
||||
|
||||
return stmt
|
||||
}
|
||||
|
||||
func (ci *copyin) NumInput() int {
|
||||
return -1
|
||||
}
|
||||
|
||||
func (ci *copyin) Query(v []driver.Value) (r driver.Rows, err error) {
|
||||
panic("should never be called")
|
||||
}
|
||||
|
||||
func (ci *copyin) Exec(v []driver.Value) (r driver.Result, err error) {
|
||||
if ci.closed {
|
||||
return nil, errors.New("copyin query is closed")
|
||||
}
|
||||
|
||||
if len(v) == 0 {
|
||||
rowCount, err := ci.bulkcopy.Done()
|
||||
ci.closed = true
|
||||
return driver.RowsAffected(rowCount), err
|
||||
}
|
||||
|
||||
t := make([]interface{}, len(v))
|
||||
for i, val := range v {
|
||||
t[i] = val
|
||||
}
|
||||
|
||||
err = ci.bulkcopy.AddRow(t)
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
|
||||
return driver.RowsAffected(0), nil
|
||||
}
|
||||
|
||||
func (ci *copyin) Close() (err error) {
|
||||
return nil
|
||||
}
|
|
@ -1,306 +0,0 @@
|
|||
package mssql
|
||||
|
||||
import "errors"
|
||||
|
||||
// Copyright 2011 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// Type conversions for Scan.
|
||||
|
||||
// This file was imported from database.sql.convert for go 1.10.3 with minor modifications to get
|
||||
// convertAssign function
|
||||
// This function is used internally by sql to convert values during call to Scan, we need same
|
||||
// logic to return values for OUTPUT parameters.
|
||||
// TODO: sql library should instead expose function defaultCheckNamedValue to be callable by drivers
|
||||
|
||||
import (
|
||||
"database/sql"
|
||||
"database/sql/driver"
|
||||
"fmt"
|
||||
"reflect"
|
||||
"strconv"
|
||||
"time"
|
||||
)
|
||||
|
||||
var errNilPtr = errors.New("destination pointer is nil") // embedded in descriptive error
|
||||
|
||||
// convertAssign copies to dest the value in src, converting it if possible.
|
||||
// An error is returned if the copy would result in loss of information.
|
||||
// dest should be a pointer type.
|
||||
func convertAssign(dest, src interface{}) error {
|
||||
// Common cases, without reflect.
|
||||
switch s := src.(type) {
|
||||
case string:
|
||||
switch d := dest.(type) {
|
||||
case *string:
|
||||
if d == nil {
|
||||
return errNilPtr
|
||||
}
|
||||
*d = s
|
||||
return nil
|
||||
case *[]byte:
|
||||
if d == nil {
|
||||
return errNilPtr
|
||||
}
|
||||
*d = []byte(s)
|
||||
return nil
|
||||
case *sql.RawBytes:
|
||||
if d == nil {
|
||||
return errNilPtr
|
||||
}
|
||||
*d = append((*d)[:0], s...)
|
||||
return nil
|
||||
}
|
||||
case []byte:
|
||||
switch d := dest.(type) {
|
||||
case *string:
|
||||
if d == nil {
|
||||
return errNilPtr
|
||||
}
|
||||
*d = string(s)
|
||||
return nil
|
||||
case *interface{}:
|
||||
if d == nil {
|
||||
return errNilPtr
|
||||
}
|
||||
*d = cloneBytes(s)
|
||||
return nil
|
||||
case *[]byte:
|
||||
if d == nil {
|
||||
return errNilPtr
|
||||
}
|
||||
*d = cloneBytes(s)
|
||||
return nil
|
||||
case *sql.RawBytes:
|
||||
if d == nil {
|
||||
return errNilPtr
|
||||
}
|
||||
*d = s
|
||||
return nil
|
||||
}
|
||||
case time.Time:
|
||||
switch d := dest.(type) {
|
||||
case *time.Time:
|
||||
*d = s
|
||||
return nil
|
||||
case *string:
|
||||
*d = s.Format(time.RFC3339Nano)
|
||||
return nil
|
||||
case *[]byte:
|
||||
if d == nil {
|
||||
return errNilPtr
|
||||
}
|
||||
*d = []byte(s.Format(time.RFC3339Nano))
|
||||
return nil
|
||||
case *sql.RawBytes:
|
||||
if d == nil {
|
||||
return errNilPtr
|
||||
}
|
||||
*d = s.AppendFormat((*d)[:0], time.RFC3339Nano)
|
||||
return nil
|
||||
}
|
||||
case nil:
|
||||
switch d := dest.(type) {
|
||||
case *interface{}:
|
||||
if d == nil {
|
||||
return errNilPtr
|
||||
}
|
||||
*d = nil
|
||||
return nil
|
||||
case *[]byte:
|
||||
if d == nil {
|
||||
return errNilPtr
|
||||
}
|
||||
*d = nil
|
||||
return nil
|
||||
case *sql.RawBytes:
|
||||
if d == nil {
|
||||
return errNilPtr
|
||||
}
|
||||
*d = nil
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
var sv reflect.Value
|
||||
|
||||
switch d := dest.(type) {
|
||||
case *string:
|
||||
sv = reflect.ValueOf(src)
|
||||
switch sv.Kind() {
|
||||
case reflect.Bool,
|
||||
reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64,
|
||||
reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64,
|
||||
reflect.Float32, reflect.Float64:
|
||||
*d = asString(src)
|
||||
return nil
|
||||
}
|
||||
case *[]byte:
|
||||
sv = reflect.ValueOf(src)
|
||||
if b, ok := asBytes(nil, sv); ok {
|
||||
*d = b
|
||||
return nil
|
||||
}
|
||||
case *sql.RawBytes:
|
||||
sv = reflect.ValueOf(src)
|
||||
if b, ok := asBytes([]byte(*d)[:0], sv); ok {
|
||||
*d = sql.RawBytes(b)
|
||||
return nil
|
||||
}
|
||||
case *bool:
|
||||
bv, err := driver.Bool.ConvertValue(src)
|
||||
if err == nil {
|
||||
*d = bv.(bool)
|
||||
}
|
||||
return err
|
||||
case *interface{}:
|
||||
*d = src
|
||||
return nil
|
||||
}
|
||||
|
||||
if scanner, ok := dest.(sql.Scanner); ok {
|
||||
return scanner.Scan(src)
|
||||
}
|
||||
|
||||
dpv := reflect.ValueOf(dest)
|
||||
if dpv.Kind() != reflect.Ptr {
|
||||
return errors.New("destination not a pointer")
|
||||
}
|
||||
if dpv.IsNil() {
|
||||
return errNilPtr
|
||||
}
|
||||
|
||||
if !sv.IsValid() {
|
||||
sv = reflect.ValueOf(src)
|
||||
}
|
||||
|
||||
dv := reflect.Indirect(dpv)
|
||||
if sv.IsValid() && sv.Type().AssignableTo(dv.Type()) {
|
||||
switch b := src.(type) {
|
||||
case []byte:
|
||||
dv.Set(reflect.ValueOf(cloneBytes(b)))
|
||||
default:
|
||||
dv.Set(sv)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
if dv.Kind() == sv.Kind() && sv.Type().ConvertibleTo(dv.Type()) {
|
||||
dv.Set(sv.Convert(dv.Type()))
|
||||
return nil
|
||||
}
|
||||
|
||||
// The following conversions use a string value as an intermediate representation
|
||||
// to convert between various numeric types.
|
||||
//
|
||||
// This also allows scanning into user defined types such as "type Int int64".
|
||||
// For symmetry, also check for string destination types.
|
||||
switch dv.Kind() {
|
||||
case reflect.Ptr:
|
||||
if src == nil {
|
||||
dv.Set(reflect.Zero(dv.Type()))
|
||||
return nil
|
||||
} else {
|
||||
dv.Set(reflect.New(dv.Type().Elem()))
|
||||
return convertAssign(dv.Interface(), src)
|
||||
}
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
s := asString(src)
|
||||
i64, err := strconv.ParseInt(s, 10, dv.Type().Bits())
|
||||
if err != nil {
|
||||
err = strconvErr(err)
|
||||
return fmt.Errorf("converting driver.Value type %T (%q) to a %s: %v", src, s, dv.Kind(), err)
|
||||
}
|
||||
dv.SetInt(i64)
|
||||
return nil
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
||||
s := asString(src)
|
||||
u64, err := strconv.ParseUint(s, 10, dv.Type().Bits())
|
||||
if err != nil {
|
||||
err = strconvErr(err)
|
||||
return fmt.Errorf("converting driver.Value type %T (%q) to a %s: %v", src, s, dv.Kind(), err)
|
||||
}
|
||||
dv.SetUint(u64)
|
||||
return nil
|
||||
case reflect.Float32, reflect.Float64:
|
||||
s := asString(src)
|
||||
f64, err := strconv.ParseFloat(s, dv.Type().Bits())
|
||||
if err != nil {
|
||||
err = strconvErr(err)
|
||||
return fmt.Errorf("converting driver.Value type %T (%q) to a %s: %v", src, s, dv.Kind(), err)
|
||||
}
|
||||
dv.SetFloat(f64)
|
||||
return nil
|
||||
case reflect.String:
|
||||
switch v := src.(type) {
|
||||
case string:
|
||||
dv.SetString(v)
|
||||
return nil
|
||||
case []byte:
|
||||
dv.SetString(string(v))
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
return fmt.Errorf("unsupported Scan, storing driver.Value type %T into type %T", src, dest)
|
||||
}
|
||||
|
||||
func strconvErr(err error) error {
|
||||
if ne, ok := err.(*strconv.NumError); ok {
|
||||
return ne.Err
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
func cloneBytes(b []byte) []byte {
|
||||
if b == nil {
|
||||
return nil
|
||||
} else {
|
||||
c := make([]byte, len(b))
|
||||
copy(c, b)
|
||||
return c
|
||||
}
|
||||
}
|
||||
|
||||
func asString(src interface{}) string {
|
||||
switch v := src.(type) {
|
||||
case string:
|
||||
return v
|
||||
case []byte:
|
||||
return string(v)
|
||||
}
|
||||
rv := reflect.ValueOf(src)
|
||||
switch rv.Kind() {
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
return strconv.FormatInt(rv.Int(), 10)
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
||||
return strconv.FormatUint(rv.Uint(), 10)
|
||||
case reflect.Float64:
|
||||
return strconv.FormatFloat(rv.Float(), 'g', -1, 64)
|
||||
case reflect.Float32:
|
||||
return strconv.FormatFloat(rv.Float(), 'g', -1, 32)
|
||||
case reflect.Bool:
|
||||
return strconv.FormatBool(rv.Bool())
|
||||
}
|
||||
return fmt.Sprintf("%v", src)
|
||||
}
|
||||
|
||||
func asBytes(buf []byte, rv reflect.Value) (b []byte, ok bool) {
|
||||
switch rv.Kind() {
|
||||
case reflect.Int, reflect.Int8, reflect.Int16, reflect.Int32, reflect.Int64:
|
||||
return strconv.AppendInt(buf, rv.Int(), 10), true
|
||||
case reflect.Uint, reflect.Uint8, reflect.Uint16, reflect.Uint32, reflect.Uint64:
|
||||
return strconv.AppendUint(buf, rv.Uint(), 10), true
|
||||
case reflect.Float32:
|
||||
return strconv.AppendFloat(buf, rv.Float(), 'g', -1, 32), true
|
||||
case reflect.Float64:
|
||||
return strconv.AppendFloat(buf, rv.Float(), 'g', -1, 64), true
|
||||
case reflect.Bool:
|
||||
return strconv.AppendBool(buf, rv.Bool()), true
|
||||
case reflect.String:
|
||||
s := rv.String()
|
||||
return append(buf, s...), true
|
||||
}
|
||||
return
|
||||
}
|
|
@ -1,131 +0,0 @@
|
|||
package mssql
|
||||
|
||||
import (
|
||||
"encoding/binary"
|
||||
"errors"
|
||||
"math"
|
||||
"math/big"
|
||||
)
|
||||
|
||||
// http://msdn.microsoft.com/en-us/library/ee780893.aspx
|
||||
type Decimal struct {
|
||||
integer [4]uint32
|
||||
positive bool
|
||||
prec uint8
|
||||
scale uint8
|
||||
}
|
||||
|
||||
var scaletblflt64 [39]float64
|
||||
|
||||
func (d Decimal) ToFloat64() float64 {
|
||||
val := float64(0)
|
||||
for i := 3; i >= 0; i-- {
|
||||
val *= 0x100000000
|
||||
val += float64(d.integer[i])
|
||||
}
|
||||
if !d.positive {
|
||||
val = -val
|
||||
}
|
||||
if d.scale != 0 {
|
||||
val /= scaletblflt64[d.scale]
|
||||
}
|
||||
return val
|
||||
}
|
||||
|
||||
const autoScale = 100
|
||||
|
||||
func Float64ToDecimal(f float64) (Decimal, error) {
|
||||
return Float64ToDecimalScale(f, autoScale)
|
||||
}
|
||||
|
||||
func Float64ToDecimalScale(f float64, scale uint8) (Decimal, error) {
|
||||
var dec Decimal
|
||||
if math.IsNaN(f) {
|
||||
return dec, errors.New("NaN")
|
||||
}
|
||||
if math.IsInf(f, 0) {
|
||||
return dec, errors.New("Infinity can't be converted to decimal")
|
||||
}
|
||||
dec.positive = f >= 0
|
||||
if !dec.positive {
|
||||
f = math.Abs(f)
|
||||
}
|
||||
if f > 3.402823669209385e+38 {
|
||||
return dec, errors.New("Float value is out of range")
|
||||
}
|
||||
dec.prec = 20
|
||||
var integer float64
|
||||
for dec.scale = 0; dec.scale <= scale; dec.scale++ {
|
||||
integer = f * scaletblflt64[dec.scale]
|
||||
_, frac := math.Modf(integer)
|
||||
if frac == 0 && scale == autoScale {
|
||||
break
|
||||
}
|
||||
}
|
||||
for i := 0; i < 4; i++ {
|
||||
mod := math.Mod(integer, 0x100000000)
|
||||
integer -= mod
|
||||
integer /= 0x100000000
|
||||
dec.integer[i] = uint32(mod)
|
||||
}
|
||||
return dec, nil
|
||||
}
|
||||
|
||||
func init() {
|
||||
var acc float64 = 1
|
||||
for i := 0; i <= 38; i++ {
|
||||
scaletblflt64[i] = acc
|
||||
acc *= 10
|
||||
}
|
||||
}
|
||||
|
||||
func (d Decimal) BigInt() big.Int {
|
||||
bytes := make([]byte, 16)
|
||||
binary.BigEndian.PutUint32(bytes[0:4], d.integer[3])
|
||||
binary.BigEndian.PutUint32(bytes[4:8], d.integer[2])
|
||||
binary.BigEndian.PutUint32(bytes[8:12], d.integer[1])
|
||||
binary.BigEndian.PutUint32(bytes[12:16], d.integer[0])
|
||||
var x big.Int
|
||||
x.SetBytes(bytes)
|
||||
if !d.positive {
|
||||
x.Neg(&x)
|
||||
}
|
||||
return x
|
||||
}
|
||||
|
||||
func (d Decimal) Bytes() []byte {
|
||||
x := d.BigInt()
|
||||
return scaleBytes(x.String(), d.scale)
|
||||
}
|
||||
|
||||
func (d Decimal) UnscaledBytes() []byte {
|
||||
x := d.BigInt()
|
||||
return x.Bytes()
|
||||
}
|
||||
|
||||
func scaleBytes(s string, scale uint8) []byte {
|
||||
z := make([]byte, 0, len(s)+1)
|
||||
if s[0] == '-' || s[0] == '+' {
|
||||
z = append(z, byte(s[0]))
|
||||
s = s[1:]
|
||||
}
|
||||
pos := len(s) - int(scale)
|
||||
if pos <= 0 {
|
||||
z = append(z, byte('0'))
|
||||
} else if pos > 0 {
|
||||
z = append(z, []byte(s[:pos])...)
|
||||
}
|
||||
if scale > 0 {
|
||||
z = append(z, byte('.'))
|
||||
for pos < 0 {
|
||||
z = append(z, byte('0'))
|
||||
pos++
|
||||
}
|
||||
z = append(z, []byte(s[pos:])...)
|
||||
}
|
||||
return z
|
||||
}
|
||||
|
||||
func (d Decimal) String() string {
|
||||
return string(d.Bytes())
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
// package mssql implements the TDS protocol used to connect to MS SQL Server (sqlserver)
|
||||
// database servers.
|
||||
//
|
||||
// This package registers the driver:
|
||||
// sqlserver: uses native "@" parameter placeholder names and does no pre-processing.
|
||||
//
|
||||
// If the ordinal position is used for query parameters, identifiers will be named
|
||||
// "@p1", "@p2", ... "@pN".
|
||||
//
|
||||
// Please refer to the README for the format of the DSN. There are multiple DSN
|
||||
// formats accepted: ADO style, ODBC style, and URL style. The following is an
|
||||
// example of a URL style DSN:
|
||||
// sqlserver://sa:mypass@localhost:1234?database=master&connection+timeout=30
|
||||
package mssql
|
|
@ -1,73 +0,0 @@
|
|||
package mssql
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
// Error represents an SQL Server error. This
|
||||
// type includes methods for reading the contents
|
||||
// of the struct, which allows calling programs
|
||||
// to check for specific error conditions without
|
||||
// having to import this package directly.
|
||||
type Error struct {
|
||||
Number int32
|
||||
State uint8
|
||||
Class uint8
|
||||
Message string
|
||||
ServerName string
|
||||
ProcName string
|
||||
LineNo int32
|
||||
}
|
||||
|
||||
func (e Error) Error() string {
|
||||
return "mssql: " + e.Message
|
||||
}
|
||||
|
||||
// SQLErrorNumber returns the SQL Server error number.
|
||||
func (e Error) SQLErrorNumber() int32 {
|
||||
return e.Number
|
||||
}
|
||||
|
||||
func (e Error) SQLErrorState() uint8 {
|
||||
return e.State
|
||||
}
|
||||
|
||||
func (e Error) SQLErrorClass() uint8 {
|
||||
return e.Class
|
||||
}
|
||||
|
||||
func (e Error) SQLErrorMessage() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
func (e Error) SQLErrorServerName() string {
|
||||
return e.ServerName
|
||||
}
|
||||
|
||||
func (e Error) SQLErrorProcName() string {
|
||||
return e.ProcName
|
||||
}
|
||||
|
||||
func (e Error) SQLErrorLineNo() int32 {
|
||||
return e.LineNo
|
||||
}
|
||||
|
||||
type StreamError struct {
|
||||
Message string
|
||||
}
|
||||
|
||||
func (e StreamError) Error() string {
|
||||
return e.Message
|
||||
}
|
||||
|
||||
func streamErrorf(format string, v ...interface{}) StreamError {
|
||||
return StreamError{"Invalid TDS stream: " + fmt.Sprintf(format, v...)}
|
||||
}
|
||||
|
||||
func badStreamPanic(err error) {
|
||||
panic(err)
|
||||
}
|
||||
|
||||
func badStreamPanicf(format string, v ...interface{}) {
|
||||
panic(streamErrorf(format, v...))
|
||||
}
|
|
@ -1,10 +0,0 @@
|
|||
module github.com/denisenkom/go-mssqldb
|
||||
|
||||
go 1.11
|
||||
|
||||
require (
|
||||
cloud.google.com/go v0.37.4
|
||||
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127 // indirect
|
||||
gopkg.in/yaml.v2 v2.2.2 // indirect
|
||||
)
|
|
@ -1,168 +0,0 @@
|
|||
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
cloud.google.com/go v0.31.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
cloud.google.com/go v0.34.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
|
||||
cloud.google.com/go v0.37.2 h1:4y4L7BdHenTfZL0HervofNTHh9Ad6mNX72cQvl+5eH0=
|
||||
cloud.google.com/go v0.37.2/go.mod h1:H8IAquKe2L30IxoupDgqTaQvKSwF/c8prYHynGIWQbA=
|
||||
git.apache.org/thrift.git v0.0.0-20180902110319-2566ecd5d999/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg=
|
||||
git.apache.org/thrift.git v0.12.0/go.mod h1:fPE2ZNJGynbRyZ4dJvy6G277gSllfV2HJqblrnkyeyg=
|
||||
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
|
||||
github.com/Shopify/sarama v1.19.0/go.mod h1:FVkBWblsNy7DGZRfXLU0O9RCGt5g3g3yEuWXgklEdEo=
|
||||
github.com/Shopify/toxiproxy v2.1.4+incompatible/go.mod h1:OXgGpZ6Cli1/URJOF1DMxUHB2q5Ap20/P/eIdh4G0pI=
|
||||
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
|
||||
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
|
||||
github.com/anmitsu/go-shlex v0.0.0-20161002113705-648efa622239/go.mod h1:2FmKhYUyUczH0OGQWaF5ceTx0UBShxjsH6f8oGKYe2c=
|
||||
github.com/apache/thrift v0.12.0/go.mod h1:cp2SuWMxlEZw2r+iP2GNCdIi4C1qmUzdZFSVb+bacwQ=
|
||||
github.com/beorn7/perks v0.0.0-20180321164747-3a771d992973/go.mod h1:Dwedo/Wpr24TaqPxmxbtue+5NUziq4I4S80YR8gNf3Q=
|
||||
github.com/bradfitz/go-smtpd v0.0.0-20170404230938-deb6d6237625/go.mod h1:HYsPBTaaSFSlLx/70C2HPIMNZpVV8+vt/A+FMnYP11g=
|
||||
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
|
||||
github.com/coreos/go-systemd v0.0.0-20181012123002-c6f51f82210d/go.mod h1:F5haX7vjVVG0kc13fIWeqUViNPyEJxv/OmvnBo0Yme4=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/eapache/go-resiliency v1.1.0/go.mod h1:kFI+JgMyC7bLPUVY133qvEBtVayf5mFgVsvEsIPBvNs=
|
||||
github.com/eapache/go-xerial-snappy v0.0.0-20180814174437-776d5712da21/go.mod h1:+020luEh2TKB4/GOp8oxxtq0Daoen/Cii55CzbTV6DU=
|
||||
github.com/eapache/queue v1.1.0/go.mod h1:6eCeP0CKFpHLu8blIFXhExK/dRa7WDZfr6jVFPTqq+I=
|
||||
github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc=
|
||||
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
|
||||
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
|
||||
github.com/gliderlabs/ssh v0.1.1/go.mod h1:U7qILu1NlMHj9FlMhZLlkCdDnU1DBEAqr0aevW3Awn0=
|
||||
github.com/go-kit/kit v0.8.0/go.mod h1:xBxKIO96dXMWWy0MnWVtmwkA9/13aqxPnvrjFYMA2as=
|
||||
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
|
||||
github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
|
||||
github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
||||
github.com/gogo/protobuf v1.2.0/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
|
||||
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
|
||||
github.com/golang/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:tluoj9z5200jBnyusfRPU2LqT6J+DAorxEvtC7LHB+E=
|
||||
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||
github.com/golang/mock v1.2.0/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
|
||||
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
|
||||
github.com/golang/snappy v0.0.0-20180518054509-2e65f85255db/go.mod h1:/XxbfmMg8lxefKM7IXC3fBNl/7bRcc72aCRzEWrmP2Q=
|
||||
github.com/google/btree v0.0.0-20180813153112-4030bb1f1f0c/go.mod h1:lNA+9X1NB3Zf8V7Ke586lFgjr2dZNuvo3lPJSGZ5JPQ=
|
||||
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
|
||||
github.com/google/go-github v17.0.0+incompatible/go.mod h1:zLgOLi98H3fifZn+44m+umXrS52loVEgC2AApnigrVQ=
|
||||
github.com/google/go-querystring v1.0.0/go.mod h1:odCYkC5MyYFN7vkCjXpyrEuKhc/BUO6wN/zVPAxq5ck=
|
||||
github.com/google/martian v2.1.0+incompatible/go.mod h1:9I4somxYTbIHy5NJKHRl3wXiIaQGbYVAs8BPL6v8lEs=
|
||||
github.com/google/pprof v0.0.0-20181206194817-3ea8567a2e57/go.mod h1:zfwlbNMJ+OItoe0UupaVj+oy1omPYYDuagoSzA8v9mc=
|
||||
github.com/googleapis/gax-go v2.0.0+incompatible/go.mod h1:SFVmujtThgffbyetf+mdk2eWhX2bMyUtNHzFKcPA9HY=
|
||||
github.com/googleapis/gax-go/v2 v2.0.4/go.mod h1:0Wqv26UfaUD9n4G6kQubkQ+KchISgw+vpHVxEJEs9eg=
|
||||
github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51q0aT7Yg=
|
||||
github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
|
||||
github.com/gregjones/httpcache v0.0.0-20180305231024-9cad4c3443a7/go.mod h1:FecbI9+v66THATjSRHfNgh1IVFe/9kFxbXtjV0ctIMA=
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.5.0/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw=
|
||||
github.com/grpc-ecosystem/grpc-gateway v1.6.2/go.mod h1:RSKVYQBd5MCa4OVpNdGskqpgL2+G+NZTnrVHpWWfpdw=
|
||||
github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
|
||||
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
|
||||
github.com/jellevandenhooff/dkim v0.0.0-20150330215556-f50fe3d243e1/go.mod h1:E0B/fFc00Y+Rasa88328GlI/XbtyysCtTHZS8h7IrBU=
|
||||
github.com/jstemmer/go-junit-report v0.0.0-20190106144839-af01ea7f8024/go.mod h1:6v2b51hI/fHJwM22ozAgKL4VKDeJcHhJFhtBdhmNjmU=
|
||||
github.com/julienschmidt/httprouter v1.2.0/go.mod h1:SYymIcj16QtmaHHD7aYtjjsJG7VTCxuUUipMqKk8s4w=
|
||||
github.com/kisielk/gotool v1.0.0/go.mod h1:XhKaO+MFFWcvkIS/tQcRk01m1F5IRFswLeQ+oQHNcck=
|
||||
github.com/konsorten/go-windows-terminal-sequences v1.0.1/go.mod h1:T0+1ngSBFLxvqU3pZ+m/2kptfBszLMUkC4ZK/EgS/cQ=
|
||||
github.com/kr/logfmt v0.0.0-20140226030751-b84e30acd515/go.mod h1:+0opPa2QZZtGFBFZlji/RkVcI2GknAs/DXo4wKdlNEc=
|
||||
github.com/kr/pty v1.1.3/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
|
||||
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
|
||||
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
|
||||
github.com/onsi/ginkgo v1.6.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/ginkgo v1.7.0/go.mod h1:lLunBs/Ym6LB5Z9jYTR76FiuTmxDTDusOGeTQH+WWjE=
|
||||
github.com/onsi/gomega v1.4.3/go.mod h1:ex+gbHU/CVuBBDIJjb2X0qEXbFg53c61hWP/1CpauHY=
|
||||
github.com/openzipkin/zipkin-go v0.1.1/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8=
|
||||
github.com/openzipkin/zipkin-go v0.1.3/go.mod h1:NtoC/o8u3JlF1lSlyPNswIbeQH9bJTmOf0Erfk+hxe8=
|
||||
github.com/openzipkin/zipkin-go v0.1.6/go.mod h1:QgAqvLzwWbR/WpD4A3cGpPtJrZXNIiJc5AZX7/PBEpw=
|
||||
github.com/pierrec/lz4 v2.0.5+incompatible/go.mod h1:pdkljMzZIN41W+lC3N2tnIh5sFi+IEE17M5jbnwPHcY=
|
||||
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/prometheus/client_golang v0.8.0/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
|
||||
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
|
||||
github.com/prometheus/client_golang v0.9.3-0.20190127221311-3c4408c8b829/go.mod h1:p2iRAGwDERtqlqzRXnrOVns+ignqQo//hLXqYxZYVNs=
|
||||
github.com/prometheus/client_model v0.0.0-20180712105110-5c3871d89910/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
|
||||
github.com/prometheus/client_model v0.0.0-20190115171406-56726106282f/go.mod h1:MbSGuTsp3dbXC40dX6PRTWyKYBIrTGTE9sqQNg2J8bo=
|
||||
github.com/prometheus/common v0.0.0-20180801064454-c7de2306084e/go.mod h1:daVV7qP5qjZbuso7PdcryaAu0sAZbrN9i7WWcTMWvro=
|
||||
github.com/prometheus/common v0.2.0/go.mod h1:TNfzLD0ON7rHzMJeJkieUDPYmFC7Snx/y86RQel1bk4=
|
||||
github.com/prometheus/procfs v0.0.0-20180725123919-05ee40e3a273/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||
github.com/prometheus/procfs v0.0.0-20181005140218-185b4288413d/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||
github.com/prometheus/procfs v0.0.0-20190117184657-bf6a532e95b1/go.mod h1:c3At6R/oaqEKCNdg8wHV1ftS6bRYblBhIjjI8uT2IGk=
|
||||
github.com/rcrowley/go-metrics v0.0.0-20181016184325-3113b8401b8a/go.mod h1:bCqnVzQkZxMG4s8nGwiZ5l3QUCyqpo9Y+/ZMZ9VjZe4=
|
||||
github.com/sirupsen/logrus v1.2.0/go.mod h1:LxeOpSwHxABJmUn/MG1IvRgCAasNZTLOkJPxbbu5VWo=
|
||||
github.com/stretchr/objx v0.1.1/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||
github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXfy6kDkUVs=
|
||||
github.com/tarm/serial v0.0.0-20180830185346-98f6abe2eb07/go.mod h1:kDXzergiv9cbyO7IOYJZWg1U88JhDg3PB6klq9Hg2pA=
|
||||
go.opencensus.io v0.18.0/go.mod h1:vKdFvxhtzZ9onBp9VKHK8z/sRpBMnKAsufL7wlDrCOA=
|
||||
go.opencensus.io v0.19.1/go.mod h1:gug0GbSHa8Pafr0d2urOSgoXHZ6x/RUlaiT0d9pqb4A=
|
||||
go.opencensus.io v0.19.2/go.mod h1:NO/8qkisMZLZ1FCsKNqtJPwc8/TaclWyY0B6wcYNg9M=
|
||||
go4.org v0.0.0-20180809161055-417644f6feb5/go.mod h1:MkTOUMDaeVYJUOUsaDXIhWPZYa1yOyC1qaOBpL57BhE=
|
||||
golang.org/x/build v0.0.0-20190314133821-5284462c4bec/go.mod h1:atTaCNAy0f16Ah5aV1gMSwgiKVHwu/JncqDpuRr7lS4=
|
||||
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20181030102418-4d3f4d9ffa16/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
|
||||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c h1:Vj5n4GlwjmQteupaxJ9+0FNOmBrHfq7vN4btdGoDZgI=
|
||||
golang.org/x/crypto v0.0.0-20190325154230-a5d413f7728c/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
|
||||
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
|
||||
golang.org/x/lint v0.0.0-20180702182130-06c8688daad7/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20181217174547-8f45f776aaf1/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
|
||||
golang.org/x/lint v0.0.0-20190301231843-5614ed5bae6f/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
|
||||
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20180906233101-161cd47e91fd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20181029044818-c44066c5c816/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20181106065722-10aee1819953/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20181114220301-adae6a3d119a/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190125091013-d26f9f9a57f3/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
|
||||
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
|
||||
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.0.0-20181017192945-9dcd33a902f4/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.0.0-20181203162652-d668ce993890/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
|
||||
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
|
||||
golang.org/x/perf v0.0.0-20180704124530-6e6d33e29852/go.mod h1:JLpeXjPJfIyPr5TlbXLkXWLhP8nz10XfvxElABhCtcw=
|
||||
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sync v0.0.0-20190227155943-e225da77a7e6/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180905080454-ebe1bf3edb33/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20180909124046-d0be0721c37e/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20181029174526-d69651ed3497/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20181116152217-5ac8a444bdc5/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20181122145206-62eef0e2fa9b/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20181218192612-074acd46bca6/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
|
||||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/text v0.3.1-0.20180807135948-17ff2d5776d2/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
|
||||
golang.org/x/time v0.0.0-20180412165947-fbb02b2291d2/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
|
||||
golang.org/x/tools v0.0.0-20180828015842-6cd1fcedba52/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20181219222714-6e267b5cc78e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
|
||||
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
|
||||
golang.org/x/tools v0.0.0-20190312170243-e65039ee4138/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
|
||||
google.golang.org/api v0.0.0-20180910000450-7ca32eb868bf/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0=
|
||||
google.golang.org/api v0.0.0-20181030000543-1d582fd0359e/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0=
|
||||
google.golang.org/api v0.0.0-20181220000619-583d854617af/go.mod h1:4mhQ8q/RsB7i+udVvVy5NUi08OU8ZlA0gRVgrF7VFY0=
|
||||
google.golang.org/api v0.2.0/go.mod h1:IfRCZScioGtypHNTlz3gFk67J8uePVW7uDTBzXuIkhU=
|
||||
google.golang.org/api v0.3.0/go.mod h1:IuvZyQh8jgscv8qWfQ4ABd8m7hEudgBFM/EdhA3BnXw=
|
||||
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
|
||||
google.golang.org/appengine v1.2.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/appengine v1.3.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
|
||||
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/genproto v0.0.0-20180831171423-11092d34479b/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/genproto v0.0.0-20181029155118-b69ba1387ce2/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
|
||||
google.golang.org/genproto v0.0.0-20181219182458-5a97ab628bfb/go.mod h1:7Ep/1NZk928CDR8SjdVbjWNpdIf6nzjE3BTgJDr2Atg=
|
||||
google.golang.org/genproto v0.0.0-20190307195333-5fe7a883aa19/go.mod h1:VzzqZJRnGkLBvHegQrXjBqPurQTc5/KpmUdxsrq26oE=
|
||||
google.golang.org/grpc v1.14.0/go.mod h1:yo6s7OP7yaDglbqo1J04qKzAhqBH6lvTonzMVmEdcZw=
|
||||
google.golang.org/grpc v1.16.0/go.mod h1:0JHn/cJsOMiMfNA9+DeHDlAU7KAAB5GDlYFpa9MZMio=
|
||||
google.golang.org/grpc v1.17.0/go.mod h1:6QZJwpn2B+Zp71q/5VxRsJ6NXXVCE5NRUHRo+f3cWCs=
|
||||
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
|
||||
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/fsnotify.v1 v1.4.7/go.mod h1:Tz8NjZHkW78fSQdbUxIjBTcgA1z1m8ZHf0WmKUhAMys=
|
||||
gopkg.in/inf.v0 v0.9.1/go.mod h1:cWUDdTG/fYaXco+Dcufb5Vnc6Gp2YChqWtbxRZE0mXw=
|
||||
gopkg.in/tomb.v1 v1.0.0-20141024135613-dd632973f1e7/go.mod h1:dt/ZhP58zS4L8KSrWDmTeBkI65Dw0HsyUHuEVlX15mw=
|
||||
gopkg.in/yaml.v2 v2.2.1/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
|
||||
grpc.go4.org v0.0.0-20170609214715-11d0a25b4919/go.mod h1:77eQGdRu53HpSqPFJFmuJdjuHRquDANNeA4x7B8WQ9o=
|
||||
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20180920025451-e3ad64cb4ed3/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
||||
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
|
|
@ -1,113 +0,0 @@
|
|||
package cp
|
||||
|
||||
type charsetMap struct {
|
||||
sb [256]rune // single byte runes, -1 for a double byte character lead byte
|
||||
db map[int]rune // double byte runes
|
||||
}
|
||||
|
||||
func collation2charset(col Collation) *charsetMap {
|
||||
// http://msdn.microsoft.com/en-us/library/ms144250.aspx
|
||||
// http://msdn.microsoft.com/en-us/library/ms144250(v=sql.105).aspx
|
||||
switch col.SortId {
|
||||
case 30, 31, 32, 33, 34:
|
||||
return cp437
|
||||
case 40, 41, 42, 44, 49, 55, 56, 57, 58, 59, 60, 61:
|
||||
return cp850
|
||||
case 50, 51, 52, 53, 54, 71, 72, 73, 74, 75:
|
||||
return cp1252
|
||||
case 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96:
|
||||
return cp1250
|
||||
case 104, 105, 106, 107, 108:
|
||||
return cp1251
|
||||
case 112, 113, 114, 121, 124:
|
||||
return cp1253
|
||||
case 128, 129, 130:
|
||||
return cp1254
|
||||
case 136, 137, 138:
|
||||
return cp1255
|
||||
case 144, 145, 146:
|
||||
return cp1256
|
||||
case 152, 153, 154, 155, 156, 157, 158, 159, 160:
|
||||
return cp1257
|
||||
case 183, 184, 185, 186:
|
||||
return cp1252
|
||||
case 192, 193:
|
||||
return cp932
|
||||
case 194, 195:
|
||||
return cp949
|
||||
case 196, 197:
|
||||
return cp950
|
||||
case 198, 199:
|
||||
return cp936
|
||||
case 200:
|
||||
return cp932
|
||||
case 201:
|
||||
return cp949
|
||||
case 202:
|
||||
return cp950
|
||||
case 203:
|
||||
return cp936
|
||||
case 204, 205, 206:
|
||||
return cp874
|
||||
case 210, 211, 212, 213, 214, 215, 216, 217:
|
||||
return cp1252
|
||||
}
|
||||
// http://technet.microsoft.com/en-us/library/aa176553(v=sql.80).aspx
|
||||
switch col.getLcid() {
|
||||
case 0x001e, 0x041e:
|
||||
return cp874
|
||||
case 0x0411, 0x10411:
|
||||
return cp932
|
||||
case 0x0804, 0x1004, 0x20804:
|
||||
return cp936
|
||||
case 0x0012, 0x0412:
|
||||
return cp949
|
||||
case 0x0404, 0x1404, 0x0c04, 0x7c04, 0x30404:
|
||||
return cp950
|
||||
case 0x041c, 0x041a, 0x0405, 0x040e, 0x104e, 0x0415, 0x0418, 0x041b, 0x0424, 0x1040e:
|
||||
return cp1250
|
||||
case 0x0423, 0x0402, 0x042f, 0x0419, 0x081a, 0x0c1a, 0x0422, 0x043f, 0x0444, 0x082c:
|
||||
return cp1251
|
||||
case 0x0408:
|
||||
return cp1253
|
||||
case 0x041f, 0x042c, 0x0443:
|
||||
return cp1254
|
||||
case 0x040d:
|
||||
return cp1255
|
||||
case 0x0401, 0x0801, 0xc01, 0x1001, 0x1401, 0x1801, 0x1c01, 0x2001, 0x2401, 0x2801, 0x2c01, 0x3001, 0x3401, 0x3801, 0x3c01, 0x4001, 0x0429, 0x0420:
|
||||
return cp1256
|
||||
case 0x0425, 0x0426, 0x0427, 0x0827:
|
||||
return cp1257
|
||||
case 0x042a:
|
||||
return cp1258
|
||||
case 0x0439, 0x045a, 0x0465:
|
||||
return nil
|
||||
}
|
||||
return cp1252
|
||||
}
|
||||
|
||||
func CharsetToUTF8(col Collation, s []byte) string {
|
||||
cm := collation2charset(col)
|
||||
if cm == nil {
|
||||
return string(s)
|
||||
}
|
||||
buf := make([]rune, 0, len(s))
|
||||
for i := 0; i < len(s); i++ {
|
||||
ch := cm.sb[s[i]]
|
||||
if ch == -1 {
|
||||
if i+1 == len(s) {
|
||||
ch = 0xfffd
|
||||
} else {
|
||||
n := int(s[i+1]) + (int(s[i]) << 8)
|
||||
i++
|
||||
var ok bool
|
||||
ch, ok = cm.db[n]
|
||||
if !ok {
|
||||
ch = 0xfffd
|
||||
}
|
||||
}
|
||||
}
|
||||
buf = append(buf, ch)
|
||||
}
|
||||
return string(buf)
|
||||
}
|
|
@ -1,20 +0,0 @@
|
|||
package cp
|
||||
|
||||
// http://msdn.microsoft.com/en-us/library/dd340437.aspx
|
||||
|
||||
type Collation struct {
|
||||
LcidAndFlags uint32
|
||||
SortId uint8
|
||||
}
|
||||
|
||||
func (c Collation) getLcid() uint32 {
|
||||
return c.LcidAndFlags & 0x000fffff
|
||||
}
|
||||
|
||||
func (c Collation) getFlags() uint32 {
|
||||
return (c.LcidAndFlags & 0x0ff00000) >> 20
|
||||
}
|
||||
|
||||
func (c Collation) getVersion() uint32 {
|
||||
return (c.LcidAndFlags & 0xf0000000) >> 28
|
||||
}
|
|
@ -1,262 +0,0 @@
|
|||
package cp
|
||||
|
||||
var cp1250 *charsetMap = &charsetMap{
|
||||
sb: [256]rune{
|
||||
0x0000, //NULL
|
||||
0x0001, //START OF HEADING
|
||||
0x0002, //START OF TEXT
|
||||
0x0003, //END OF TEXT
|
||||
0x0004, //END OF TRANSMISSION
|
||||
0x0005, //ENQUIRY
|
||||
0x0006, //ACKNOWLEDGE
|
||||
0x0007, //BELL
|
||||
0x0008, //BACKSPACE
|
||||
0x0009, //HORIZONTAL TABULATION
|
||||
0x000A, //LINE FEED
|
||||
0x000B, //VERTICAL TABULATION
|
||||
0x000C, //FORM FEED
|
||||
0x000D, //CARRIAGE RETURN
|
||||
0x000E, //SHIFT OUT
|
||||
0x000F, //SHIFT IN
|
||||
0x0010, //DATA LINK ESCAPE
|
||||
0x0011, //DEVICE CONTROL ONE
|
||||
0x0012, //DEVICE CONTROL TWO
|
||||
0x0013, //DEVICE CONTROL THREE
|
||||
0x0014, //DEVICE CONTROL FOUR
|
||||
0x0015, //NEGATIVE ACKNOWLEDGE
|
||||
0x0016, //SYNCHRONOUS IDLE
|
||||
0x0017, //END OF TRANSMISSION BLOCK
|
||||
0x0018, //CANCEL
|
||||
0x0019, //END OF MEDIUM
|
||||
0x001A, //SUBSTITUTE
|
||||
0x001B, //ESCAPE
|
||||
0x001C, //FILE SEPARATOR
|
||||
0x001D, //GROUP SEPARATOR
|
||||
0x001E, //RECORD SEPARATOR
|
||||
0x001F, //UNIT SEPARATOR
|
||||
0x0020, //SPACE
|
||||
0x0021, //EXCLAMATION MARK
|
||||
0x0022, //QUOTATION MARK
|
||||
0x0023, //NUMBER SIGN
|
||||
0x0024, //DOLLAR SIGN
|
||||
0x0025, //PERCENT SIGN
|
||||
0x0026, //AMPERSAND
|
||||
0x0027, //APOSTROPHE
|
||||
0x0028, //LEFT PARENTHESIS
|
||||
0x0029, //RIGHT PARENTHESIS
|
||||
0x002A, //ASTERISK
|
||||
0x002B, //PLUS SIGN
|
||||
0x002C, //COMMA
|
||||
0x002D, //HYPHEN-MINUS
|
||||
0x002E, //FULL STOP
|
||||
0x002F, //SOLIDUS
|
||||
0x0030, //DIGIT ZERO
|
||||
0x0031, //DIGIT ONE
|
||||
0x0032, //DIGIT TWO
|
||||
0x0033, //DIGIT THREE
|
||||
0x0034, //DIGIT FOUR
|
||||
0x0035, //DIGIT FIVE
|
||||
0x0036, //DIGIT SIX
|
||||
0x0037, //DIGIT SEVEN
|
||||
0x0038, //DIGIT EIGHT
|
||||
0x0039, //DIGIT NINE
|
||||
0x003A, //COLON
|
||||
0x003B, //SEMICOLON
|
||||
0x003C, //LESS-THAN SIGN
|
||||
0x003D, //EQUALS SIGN
|
||||
0x003E, //GREATER-THAN SIGN
|
||||
0x003F, //QUESTION MARK
|
||||
0x0040, //COMMERCIAL AT
|
||||
0x0041, //LATIN CAPITAL LETTER A
|
||||
0x0042, //LATIN CAPITAL LETTER B
|
||||
0x0043, //LATIN CAPITAL LETTER C
|
||||
0x0044, //LATIN CAPITAL LETTER D
|
||||
0x0045, //LATIN CAPITAL LETTER E
|
||||
0x0046, //LATIN CAPITAL LETTER F
|
||||
0x0047, //LATIN CAPITAL LETTER G
|
||||
0x0048, //LATIN CAPITAL LETTER H
|
||||
0x0049, //LATIN CAPITAL LETTER I
|
||||
0x004A, //LATIN CAPITAL LETTER J
|
||||
0x004B, //LATIN CAPITAL LETTER K
|
||||
0x004C, //LATIN CAPITAL LETTER L
|
||||
0x004D, //LATIN CAPITAL LETTER M
|
||||
0x004E, //LATIN CAPITAL LETTER N
|
||||
0x004F, //LATIN CAPITAL LETTER O
|
||||
0x0050, //LATIN CAPITAL LETTER P
|
||||
0x0051, //LATIN CAPITAL LETTER Q
|
||||
0x0052, //LATIN CAPITAL LETTER R
|
||||
0x0053, //LATIN CAPITAL LETTER S
|
||||
0x0054, //LATIN CAPITAL LETTER T
|
||||
0x0055, //LATIN CAPITAL LETTER U
|
||||
0x0056, //LATIN CAPITAL LETTER V
|
||||
0x0057, //LATIN CAPITAL LETTER W
|
||||
0x0058, //LATIN CAPITAL LETTER X
|
||||
0x0059, //LATIN CAPITAL LETTER Y
|
||||
0x005A, //LATIN CAPITAL LETTER Z
|
||||
0x005B, //LEFT SQUARE BRACKET
|
||||
0x005C, //REVERSE SOLIDUS
|
||||
0x005D, //RIGHT SQUARE BRACKET
|
||||
0x005E, //CIRCUMFLEX ACCENT
|
||||
0x005F, //LOW LINE
|
||||
0x0060, //GRAVE ACCENT
|
||||
0x0061, //LATIN SMALL LETTER A
|
||||
0x0062, //LATIN SMALL LETTER B
|
||||
0x0063, //LATIN SMALL LETTER C
|
||||
0x0064, //LATIN SMALL LETTER D
|
||||
0x0065, //LATIN SMALL LETTER E
|
||||
0x0066, //LATIN SMALL LETTER F
|
||||
0x0067, //LATIN SMALL LETTER G
|
||||
0x0068, //LATIN SMALL LETTER H
|
||||
0x0069, //LATIN SMALL LETTER I
|
||||
0x006A, //LATIN SMALL LETTER J
|
||||
0x006B, //LATIN SMALL LETTER K
|
||||
0x006C, //LATIN SMALL LETTER L
|
||||
0x006D, //LATIN SMALL LETTER M
|
||||
0x006E, //LATIN SMALL LETTER N
|
||||
0x006F, //LATIN SMALL LETTER O
|
||||
0x0070, //LATIN SMALL LETTER P
|
||||
0x0071, //LATIN SMALL LETTER Q
|
||||
0x0072, //LATIN SMALL LETTER R
|
||||
0x0073, //LATIN SMALL LETTER S
|
||||
0x0074, //LATIN SMALL LETTER T
|
||||
0x0075, //LATIN SMALL LETTER U
|
||||
0x0076, //LATIN SMALL LETTER V
|
||||
0x0077, //LATIN SMALL LETTER W
|
||||
0x0078, //LATIN SMALL LETTER X
|
||||
0x0079, //LATIN SMALL LETTER Y
|
||||
0x007A, //LATIN SMALL LETTER Z
|
||||
0x007B, //LEFT CURLY BRACKET
|
||||
0x007C, //VERTICAL LINE
|
||||
0x007D, //RIGHT CURLY BRACKET
|
||||
0x007E, //TILDE
|
||||
0x007F, //DELETE
|
||||
0x20AC, //EURO SIGN
|
||||
0xFFFD, //UNDEFINED
|
||||
0x201A, //SINGLE LOW-9 QUOTATION MARK
|
||||
0xFFFD, //UNDEFINED
|
||||
0x201E, //DOUBLE LOW-9 QUOTATION MARK
|
||||
0x2026, //HORIZONTAL ELLIPSIS
|
||||
0x2020, //DAGGER
|
||||
0x2021, //DOUBLE DAGGER
|
||||
0xFFFD, //UNDEFINED
|
||||
0x2030, //PER MILLE SIGN
|
||||
0x0160, //LATIN CAPITAL LETTER S WITH CARON
|
||||
0x2039, //SINGLE LEFT-POINTING ANGLE QUOTATION MARK
|
||||
0x015A, //LATIN CAPITAL LETTER S WITH ACUTE
|
||||
0x0164, //LATIN CAPITAL LETTER T WITH CARON
|
||||
0x017D, //LATIN CAPITAL LETTER Z WITH CARON
|
||||
0x0179, //LATIN CAPITAL LETTER Z WITH ACUTE
|
||||
0xFFFD, //UNDEFINED
|
||||
0x2018, //LEFT SINGLE QUOTATION MARK
|
||||
0x2019, //RIGHT SINGLE QUOTATION MARK
|
||||
0x201C, //LEFT DOUBLE QUOTATION MARK
|
||||
0x201D, //RIGHT DOUBLE QUOTATION MARK
|
||||
0x2022, //BULLET
|
||||
0x2013, //EN DASH
|
||||
0x2014, //EM DASH
|
||||
0xFFFD, //UNDEFINED
|
||||
0x2122, //TRADE MARK SIGN
|
||||
0x0161, //LATIN SMALL LETTER S WITH CARON
|
||||
0x203A, //SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
|
||||
0x015B, //LATIN SMALL LETTER S WITH ACUTE
|
||||
0x0165, //LATIN SMALL LETTER T WITH CARON
|
||||
0x017E, //LATIN SMALL LETTER Z WITH CARON
|
||||
0x017A, //LATIN SMALL LETTER Z WITH ACUTE
|
||||
0x00A0, //NO-BREAK SPACE
|
||||
0x02C7, //CARON
|
||||
0x02D8, //BREVE
|
||||
0x0141, //LATIN CAPITAL LETTER L WITH STROKE
|
||||
0x00A4, //CURRENCY SIGN
|
||||
0x0104, //LATIN CAPITAL LETTER A WITH OGONEK
|
||||
0x00A6, //BROKEN BAR
|
||||
0x00A7, //SECTION SIGN
|
||||
0x00A8, //DIAERESIS
|
||||
0x00A9, //COPYRIGHT SIGN
|
||||
0x015E, //LATIN CAPITAL LETTER S WITH CEDILLA
|
||||
0x00AB, //LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
|
||||
0x00AC, //NOT SIGN
|
||||
0x00AD, //SOFT HYPHEN
|
||||
0x00AE, //REGISTERED SIGN
|
||||
0x017B, //LATIN CAPITAL LETTER Z WITH DOT ABOVE
|
||||
0x00B0, //DEGREE SIGN
|
||||
0x00B1, //PLUS-MINUS SIGN
|
||||
0x02DB, //OGONEK
|
||||
0x0142, //LATIN SMALL LETTER L WITH STROKE
|
||||
0x00B4, //ACUTE ACCENT
|
||||
0x00B5, //MICRO SIGN
|
||||
0x00B6, //PILCROW SIGN
|
||||
0x00B7, //MIDDLE DOT
|
||||
0x00B8, //CEDILLA
|
||||
0x0105, //LATIN SMALL LETTER A WITH OGONEK
|
||||
0x015F, //LATIN SMALL LETTER S WITH CEDILLA
|
||||
0x00BB, //RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
|
||||
0x013D, //LATIN CAPITAL LETTER L WITH CARON
|
||||
0x02DD, //DOUBLE ACUTE ACCENT
|
||||
0x013E, //LATIN SMALL LETTER L WITH CARON
|
||||
0x017C, //LATIN SMALL LETTER Z WITH DOT ABOVE
|
||||
0x0154, //LATIN CAPITAL LETTER R WITH ACUTE
|
||||
0x00C1, //LATIN CAPITAL LETTER A WITH ACUTE
|
||||
0x00C2, //LATIN CAPITAL LETTER A WITH CIRCUMFLEX
|
||||
0x0102, //LATIN CAPITAL LETTER A WITH BREVE
|
||||
0x00C4, //LATIN CAPITAL LETTER A WITH DIAERESIS
|
||||
0x0139, //LATIN CAPITAL LETTER L WITH ACUTE
|
||||
0x0106, //LATIN CAPITAL LETTER C WITH ACUTE
|
||||
0x00C7, //LATIN CAPITAL LETTER C WITH CEDILLA
|
||||
0x010C, //LATIN CAPITAL LETTER C WITH CARON
|
||||
0x00C9, //LATIN CAPITAL LETTER E WITH ACUTE
|
||||
0x0118, //LATIN CAPITAL LETTER E WITH OGONEK
|
||||
0x00CB, //LATIN CAPITAL LETTER E WITH DIAERESIS
|
||||
0x011A, //LATIN CAPITAL LETTER E WITH CARON
|
||||
0x00CD, //LATIN CAPITAL LETTER I WITH ACUTE
|
||||
0x00CE, //LATIN CAPITAL LETTER I WITH CIRCUMFLEX
|
||||
0x010E, //LATIN CAPITAL LETTER D WITH CARON
|
||||
0x0110, //LATIN CAPITAL LETTER D WITH STROKE
|
||||
0x0143, //LATIN CAPITAL LETTER N WITH ACUTE
|
||||
0x0147, //LATIN CAPITAL LETTER N WITH CARON
|
||||
0x00D3, //LATIN CAPITAL LETTER O WITH ACUTE
|
||||
0x00D4, //LATIN CAPITAL LETTER O WITH CIRCUMFLEX
|
||||
0x0150, //LATIN CAPITAL LETTER O WITH DOUBLE ACUTE
|
||||
0x00D6, //LATIN CAPITAL LETTER O WITH DIAERESIS
|
||||
0x00D7, //MULTIPLICATION SIGN
|
||||
0x0158, //LATIN CAPITAL LETTER R WITH CARON
|
||||
0x016E, //LATIN CAPITAL LETTER U WITH RING ABOVE
|
||||
0x00DA, //LATIN CAPITAL LETTER U WITH ACUTE
|
||||
0x0170, //LATIN CAPITAL LETTER U WITH DOUBLE ACUTE
|
||||
0x00DC, //LATIN CAPITAL LETTER U WITH DIAERESIS
|
||||
0x00DD, //LATIN CAPITAL LETTER Y WITH ACUTE
|
||||
0x0162, //LATIN CAPITAL LETTER T WITH CEDILLA
|
||||
0x00DF, //LATIN SMALL LETTER SHARP S
|
||||
0x0155, //LATIN SMALL LETTER R WITH ACUTE
|
||||
0x00E1, //LATIN SMALL LETTER A WITH ACUTE
|
||||
0x00E2, //LATIN SMALL LETTER A WITH CIRCUMFLEX
|
||||
0x0103, //LATIN SMALL LETTER A WITH BREVE
|
||||
0x00E4, //LATIN SMALL LETTER A WITH DIAERESIS
|
||||
0x013A, //LATIN SMALL LETTER L WITH ACUTE
|
||||
0x0107, //LATIN SMALL LETTER C WITH ACUTE
|
||||
0x00E7, //LATIN SMALL LETTER C WITH CEDILLA
|
||||
0x010D, //LATIN SMALL LETTER C WITH CARON
|
||||
0x00E9, //LATIN SMALL LETTER E WITH ACUTE
|
||||
0x0119, //LATIN SMALL LETTER E WITH OGONEK
|
||||
0x00EB, //LATIN SMALL LETTER E WITH DIAERESIS
|
||||
0x011B, //LATIN SMALL LETTER E WITH CARON
|
||||
0x00ED, //LATIN SMALL LETTER I WITH ACUTE
|
||||
0x00EE, //LATIN SMALL LETTER I WITH CIRCUMFLEX
|
||||
0x010F, //LATIN SMALL LETTER D WITH CARON
|
||||
0x0111, //LATIN SMALL LETTER D WITH STROKE
|
||||
0x0144, //LATIN SMALL LETTER N WITH ACUTE
|
||||
0x0148, //LATIN SMALL LETTER N WITH CARON
|
||||
0x00F3, //LATIN SMALL LETTER O WITH ACUTE
|
||||
0x00F4, //LATIN SMALL LETTER O WITH CIRCUMFLEX
|
||||
0x0151, //LATIN SMALL LETTER O WITH DOUBLE ACUTE
|
||||
0x00F6, //LATIN SMALL LETTER O WITH DIAERESIS
|
||||
0x00F7, //DIVISION SIGN
|
||||
0x0159, //LATIN SMALL LETTER R WITH CARON
|
||||
0x016F, //LATIN SMALL LETTER U WITH RING ABOVE
|
||||
0x00FA, //LATIN SMALL LETTER U WITH ACUTE
|
||||
0x0171, //LATIN SMALL LETTER U WITH DOUBLE ACUTE
|
||||
0x00FC, //LATIN SMALL LETTER U WITH DIAERESIS
|
||||
0x00FD, //LATIN SMALL LETTER Y WITH ACUTE
|
||||
0x0163, //LATIN SMALL LETTER T WITH CEDILLA
|
||||
0x02D9, //DOT ABOVE
|
||||
},
|
||||
}
|
|
@ -1,262 +0,0 @@
|
|||
package cp
|
||||
|
||||
var cp1251 *charsetMap = &charsetMap{
|
||||
sb: [256]rune{
|
||||
0x0000, //NULL
|
||||
0x0001, //START OF HEADING
|
||||
0x0002, //START OF TEXT
|
||||
0x0003, //END OF TEXT
|
||||
0x0004, //END OF TRANSMISSION
|
||||
0x0005, //ENQUIRY
|
||||
0x0006, //ACKNOWLEDGE
|
||||
0x0007, //BELL
|
||||
0x0008, //BACKSPACE
|
||||
0x0009, //HORIZONTAL TABULATION
|
||||
0x000A, //LINE FEED
|
||||
0x000B, //VERTICAL TABULATION
|
||||
0x000C, //FORM FEED
|
||||
0x000D, //CARRIAGE RETURN
|
||||
0x000E, //SHIFT OUT
|
||||
0x000F, //SHIFT IN
|
||||
0x0010, //DATA LINK ESCAPE
|
||||
0x0011, //DEVICE CONTROL ONE
|
||||
0x0012, //DEVICE CONTROL TWO
|
||||
0x0013, //DEVICE CONTROL THREE
|
||||
0x0014, //DEVICE CONTROL FOUR
|
||||
0x0015, //NEGATIVE ACKNOWLEDGE
|
||||
0x0016, //SYNCHRONOUS IDLE
|
||||
0x0017, //END OF TRANSMISSION BLOCK
|
||||
0x0018, //CANCEL
|
||||
0x0019, //END OF MEDIUM
|
||||
0x001A, //SUBSTITUTE
|
||||
0x001B, //ESCAPE
|
||||
0x001C, //FILE SEPARATOR
|
||||
0x001D, //GROUP SEPARATOR
|
||||
0x001E, //RECORD SEPARATOR
|
||||
0x001F, //UNIT SEPARATOR
|
||||
0x0020, //SPACE
|
||||
0x0021, //EXCLAMATION MARK
|
||||
0x0022, //QUOTATION MARK
|
||||
0x0023, //NUMBER SIGN
|
||||
0x0024, //DOLLAR SIGN
|
||||
0x0025, //PERCENT SIGN
|
||||
0x0026, //AMPERSAND
|
||||
0x0027, //APOSTROPHE
|
||||
0x0028, //LEFT PARENTHESIS
|
||||
0x0029, //RIGHT PARENTHESIS
|
||||
0x002A, //ASTERISK
|
||||
0x002B, //PLUS SIGN
|
||||
0x002C, //COMMA
|
||||
0x002D, //HYPHEN-MINUS
|
||||
0x002E, //FULL STOP
|
||||
0x002F, //SOLIDUS
|
||||
0x0030, //DIGIT ZERO
|
||||
0x0031, //DIGIT ONE
|
||||
0x0032, //DIGIT TWO
|
||||
0x0033, //DIGIT THREE
|
||||
0x0034, //DIGIT FOUR
|
||||
0x0035, //DIGIT FIVE
|
||||
0x0036, //DIGIT SIX
|
||||
0x0037, //DIGIT SEVEN
|
||||
0x0038, //DIGIT EIGHT
|
||||
0x0039, //DIGIT NINE
|
||||
0x003A, //COLON
|
||||
0x003B, //SEMICOLON
|
||||
0x003C, //LESS-THAN SIGN
|
||||
0x003D, //EQUALS SIGN
|
||||
0x003E, //GREATER-THAN SIGN
|
||||
0x003F, //QUESTION MARK
|
||||
0x0040, //COMMERCIAL AT
|
||||
0x0041, //LATIN CAPITAL LETTER A
|
||||
0x0042, //LATIN CAPITAL LETTER B
|
||||
0x0043, //LATIN CAPITAL LETTER C
|
||||
0x0044, //LATIN CAPITAL LETTER D
|
||||
0x0045, //LATIN CAPITAL LETTER E
|
||||
0x0046, //LATIN CAPITAL LETTER F
|
||||
0x0047, //LATIN CAPITAL LETTER G
|
||||
0x0048, //LATIN CAPITAL LETTER H
|
||||
0x0049, //LATIN CAPITAL LETTER I
|
||||
0x004A, //LATIN CAPITAL LETTER J
|
||||
0x004B, //LATIN CAPITAL LETTER K
|
||||
0x004C, //LATIN CAPITAL LETTER L
|
||||
0x004D, //LATIN CAPITAL LETTER M
|
||||
0x004E, //LATIN CAPITAL LETTER N
|
||||
0x004F, //LATIN CAPITAL LETTER O
|
||||
0x0050, //LATIN CAPITAL LETTER P
|
||||
0x0051, //LATIN CAPITAL LETTER Q
|
||||
0x0052, //LATIN CAPITAL LETTER R
|
||||
0x0053, //LATIN CAPITAL LETTER S
|
||||
0x0054, //LATIN CAPITAL LETTER T
|
||||
0x0055, //LATIN CAPITAL LETTER U
|
||||
0x0056, //LATIN CAPITAL LETTER V
|
||||
0x0057, //LATIN CAPITAL LETTER W
|
||||
0x0058, //LATIN CAPITAL LETTER X
|
||||
0x0059, //LATIN CAPITAL LETTER Y
|
||||
0x005A, //LATIN CAPITAL LETTER Z
|
||||
0x005B, //LEFT SQUARE BRACKET
|
||||
0x005C, //REVERSE SOLIDUS
|
||||
0x005D, //RIGHT SQUARE BRACKET
|
||||
0x005E, //CIRCUMFLEX ACCENT
|
||||
0x005F, //LOW LINE
|
||||
0x0060, //GRAVE ACCENT
|
||||
0x0061, //LATIN SMALL LETTER A
|
||||
0x0062, //LATIN SMALL LETTER B
|
||||
0x0063, //LATIN SMALL LETTER C
|
||||
0x0064, //LATIN SMALL LETTER D
|
||||
0x0065, //LATIN SMALL LETTER E
|
||||
0x0066, //LATIN SMALL LETTER F
|
||||
0x0067, //LATIN SMALL LETTER G
|
||||
0x0068, //LATIN SMALL LETTER H
|
||||
0x0069, //LATIN SMALL LETTER I
|
||||
0x006A, //LATIN SMALL LETTER J
|
||||
0x006B, //LATIN SMALL LETTER K
|
||||
0x006C, //LATIN SMALL LETTER L
|
||||
0x006D, //LATIN SMALL LETTER M
|
||||
0x006E, //LATIN SMALL LETTER N
|
||||
0x006F, //LATIN SMALL LETTER O
|
||||
0x0070, //LATIN SMALL LETTER P
|
||||
0x0071, //LATIN SMALL LETTER Q
|
||||
0x0072, //LATIN SMALL LETTER R
|
||||
0x0073, //LATIN SMALL LETTER S
|
||||
0x0074, //LATIN SMALL LETTER T
|
||||
0x0075, //LATIN SMALL LETTER U
|
||||
0x0076, //LATIN SMALL LETTER V
|
||||
0x0077, //LATIN SMALL LETTER W
|
||||
0x0078, //LATIN SMALL LETTER X
|
||||
0x0079, //LATIN SMALL LETTER Y
|
||||
0x007A, //LATIN SMALL LETTER Z
|
||||
0x007B, //LEFT CURLY BRACKET
|
||||
0x007C, //VERTICAL LINE
|
||||
0x007D, //RIGHT CURLY BRACKET
|
||||
0x007E, //TILDE
|
||||
0x007F, //DELETE
|
||||
0x0402, //CYRILLIC CAPITAL LETTER DJE
|
||||
0x0403, //CYRILLIC CAPITAL LETTER GJE
|
||||
0x201A, //SINGLE LOW-9 QUOTATION MARK
|
||||
0x0453, //CYRILLIC SMALL LETTER GJE
|
||||
0x201E, //DOUBLE LOW-9 QUOTATION MARK
|
||||
0x2026, //HORIZONTAL ELLIPSIS
|
||||
0x2020, //DAGGER
|
||||
0x2021, //DOUBLE DAGGER
|
||||
0x20AC, //EURO SIGN
|
||||
0x2030, //PER MILLE SIGN
|
||||
0x0409, //CYRILLIC CAPITAL LETTER LJE
|
||||
0x2039, //SINGLE LEFT-POINTING ANGLE QUOTATION MARK
|
||||
0x040A, //CYRILLIC CAPITAL LETTER NJE
|
||||
0x040C, //CYRILLIC CAPITAL LETTER KJE
|
||||
0x040B, //CYRILLIC CAPITAL LETTER TSHE
|
||||
0x040F, //CYRILLIC CAPITAL LETTER DZHE
|
||||
0x0452, //CYRILLIC SMALL LETTER DJE
|
||||
0x2018, //LEFT SINGLE QUOTATION MARK
|
||||
0x2019, //RIGHT SINGLE QUOTATION MARK
|
||||
0x201C, //LEFT DOUBLE QUOTATION MARK
|
||||
0x201D, //RIGHT DOUBLE QUOTATION MARK
|
||||
0x2022, //BULLET
|
||||
0x2013, //EN DASH
|
||||
0x2014, //EM DASH
|
||||
0xFFFD, //UNDEFINED
|
||||
0x2122, //TRADE MARK SIGN
|
||||
0x0459, //CYRILLIC SMALL LETTER LJE
|
||||
0x203A, //SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
|
||||
0x045A, //CYRILLIC SMALL LETTER NJE
|
||||
0x045C, //CYRILLIC SMALL LETTER KJE
|
||||
0x045B, //CYRILLIC SMALL LETTER TSHE
|
||||
0x045F, //CYRILLIC SMALL LETTER DZHE
|
||||
0x00A0, //NO-BREAK SPACE
|
||||
0x040E, //CYRILLIC CAPITAL LETTER SHORT U
|
||||
0x045E, //CYRILLIC SMALL LETTER SHORT U
|
||||
0x0408, //CYRILLIC CAPITAL LETTER JE
|
||||
0x00A4, //CURRENCY SIGN
|
||||
0x0490, //CYRILLIC CAPITAL LETTER GHE WITH UPTURN
|
||||
0x00A6, //BROKEN BAR
|
||||
0x00A7, //SECTION SIGN
|
||||
0x0401, //CYRILLIC CAPITAL LETTER IO
|
||||
0x00A9, //COPYRIGHT SIGN
|
||||
0x0404, //CYRILLIC CAPITAL LETTER UKRAINIAN IE
|
||||
0x00AB, //LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
|
||||
0x00AC, //NOT SIGN
|
||||
0x00AD, //SOFT HYPHEN
|
||||
0x00AE, //REGISTERED SIGN
|
||||
0x0407, //CYRILLIC CAPITAL LETTER YI
|
||||
0x00B0, //DEGREE SIGN
|
||||
0x00B1, //PLUS-MINUS SIGN
|
||||
0x0406, //CYRILLIC CAPITAL LETTER BYELORUSSIAN-UKRAINIAN I
|
||||
0x0456, //CYRILLIC SMALL LETTER BYELORUSSIAN-UKRAINIAN I
|
||||
0x0491, //CYRILLIC SMALL LETTER GHE WITH UPTURN
|
||||
0x00B5, //MICRO SIGN
|
||||
0x00B6, //PILCROW SIGN
|
||||
0x00B7, //MIDDLE DOT
|
||||
0x0451, //CYRILLIC SMALL LETTER IO
|
||||
0x2116, //NUMERO SIGN
|
||||
0x0454, //CYRILLIC SMALL LETTER UKRAINIAN IE
|
||||
0x00BB, //RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
|
||||
0x0458, //CYRILLIC SMALL LETTER JE
|
||||
0x0405, //CYRILLIC CAPITAL LETTER DZE
|
||||
0x0455, //CYRILLIC SMALL LETTER DZE
|
||||
0x0457, //CYRILLIC SMALL LETTER YI
|
||||
0x0410, //CYRILLIC CAPITAL LETTER A
|
||||
0x0411, //CYRILLIC CAPITAL LETTER BE
|
||||
0x0412, //CYRILLIC CAPITAL LETTER VE
|
||||
0x0413, //CYRILLIC CAPITAL LETTER GHE
|
||||
0x0414, //CYRILLIC CAPITAL LETTER DE
|
||||
0x0415, //CYRILLIC CAPITAL LETTER IE
|
||||
0x0416, //CYRILLIC CAPITAL LETTER ZHE
|
||||
0x0417, //CYRILLIC CAPITAL LETTER ZE
|
||||
0x0418, //CYRILLIC CAPITAL LETTER I
|
||||
0x0419, //CYRILLIC CAPITAL LETTER SHORT I
|
||||
0x041A, //CYRILLIC CAPITAL LETTER KA
|
||||
0x041B, //CYRILLIC CAPITAL LETTER EL
|
||||
0x041C, //CYRILLIC CAPITAL LETTER EM
|
||||
0x041D, //CYRILLIC CAPITAL LETTER EN
|
||||
0x041E, //CYRILLIC CAPITAL LETTER O
|
||||
0x041F, //CYRILLIC CAPITAL LETTER PE
|
||||
0x0420, //CYRILLIC CAPITAL LETTER ER
|
||||
0x0421, //CYRILLIC CAPITAL LETTER ES
|
||||
0x0422, //CYRILLIC CAPITAL LETTER TE
|
||||
0x0423, //CYRILLIC CAPITAL LETTER U
|
||||
0x0424, //CYRILLIC CAPITAL LETTER EF
|
||||
0x0425, //CYRILLIC CAPITAL LETTER HA
|
||||
0x0426, //CYRILLIC CAPITAL LETTER TSE
|
||||
0x0427, //CYRILLIC CAPITAL LETTER CHE
|
||||
0x0428, //CYRILLIC CAPITAL LETTER SHA
|
||||
0x0429, //CYRILLIC CAPITAL LETTER SHCHA
|
||||
0x042A, //CYRILLIC CAPITAL LETTER HARD SIGN
|
||||
0x042B, //CYRILLIC CAPITAL LETTER YERU
|
||||
0x042C, //CYRILLIC CAPITAL LETTER SOFT SIGN
|
||||
0x042D, //CYRILLIC CAPITAL LETTER E
|
||||
0x042E, //CYRILLIC CAPITAL LETTER YU
|
||||
0x042F, //CYRILLIC CAPITAL LETTER YA
|
||||
0x0430, //CYRILLIC SMALL LETTER A
|
||||
0x0431, //CYRILLIC SMALL LETTER BE
|
||||
0x0432, //CYRILLIC SMALL LETTER VE
|
||||
0x0433, //CYRILLIC SMALL LETTER GHE
|
||||
0x0434, //CYRILLIC SMALL LETTER DE
|
||||
0x0435, //CYRILLIC SMALL LETTER IE
|
||||
0x0436, //CYRILLIC SMALL LETTER ZHE
|
||||
0x0437, //CYRILLIC SMALL LETTER ZE
|
||||
0x0438, //CYRILLIC SMALL LETTER I
|
||||
0x0439, //CYRILLIC SMALL LETTER SHORT I
|
||||
0x043A, //CYRILLIC SMALL LETTER KA
|
||||
0x043B, //CYRILLIC SMALL LETTER EL
|
||||
0x043C, //CYRILLIC SMALL LETTER EM
|
||||
0x043D, //CYRILLIC SMALL LETTER EN
|
||||
0x043E, //CYRILLIC SMALL LETTER O
|
||||
0x043F, //CYRILLIC SMALL LETTER PE
|
||||
0x0440, //CYRILLIC SMALL LETTER ER
|
||||
0x0441, //CYRILLIC SMALL LETTER ES
|
||||
0x0442, //CYRILLIC SMALL LETTER TE
|
||||
0x0443, //CYRILLIC SMALL LETTER U
|
||||
0x0444, //CYRILLIC SMALL LETTER EF
|
||||
0x0445, //CYRILLIC SMALL LETTER HA
|
||||
0x0446, //CYRILLIC SMALL LETTER TSE
|
||||
0x0447, //CYRILLIC SMALL LETTER CHE
|
||||
0x0448, //CYRILLIC SMALL LETTER SHA
|
||||
0x0449, //CYRILLIC SMALL LETTER SHCHA
|
||||
0x044A, //CYRILLIC SMALL LETTER HARD SIGN
|
||||
0x044B, //CYRILLIC SMALL LETTER YERU
|
||||
0x044C, //CYRILLIC SMALL LETTER SOFT SIGN
|
||||
0x044D, //CYRILLIC SMALL LETTER E
|
||||
0x044E, //CYRILLIC SMALL LETTER YU
|
||||
0x044F, //CYRILLIC SMALL LETTER YA
|
||||
},
|
||||
}
|
|
@ -1,262 +0,0 @@
|
|||
package cp
|
||||
|
||||
var cp1252 *charsetMap = &charsetMap{
|
||||
sb: [256]rune{
|
||||
0x0000, //NULL
|
||||
0x0001, //START OF HEADING
|
||||
0x0002, //START OF TEXT
|
||||
0x0003, //END OF TEXT
|
||||
0x0004, //END OF TRANSMISSION
|
||||
0x0005, //ENQUIRY
|
||||
0x0006, //ACKNOWLEDGE
|
||||
0x0007, //BELL
|
||||
0x0008, //BACKSPACE
|
||||
0x0009, //HORIZONTAL TABULATION
|
||||
0x000A, //LINE FEED
|
||||
0x000B, //VERTICAL TABULATION
|
||||
0x000C, //FORM FEED
|
||||
0x000D, //CARRIAGE RETURN
|
||||
0x000E, //SHIFT OUT
|
||||
0x000F, //SHIFT IN
|
||||
0x0010, //DATA LINK ESCAPE
|
||||
0x0011, //DEVICE CONTROL ONE
|
||||
0x0012, //DEVICE CONTROL TWO
|
||||
0x0013, //DEVICE CONTROL THREE
|
||||
0x0014, //DEVICE CONTROL FOUR
|
||||
0x0015, //NEGATIVE ACKNOWLEDGE
|
||||
0x0016, //SYNCHRONOUS IDLE
|
||||
0x0017, //END OF TRANSMISSION BLOCK
|
||||
0x0018, //CANCEL
|
||||
0x0019, //END OF MEDIUM
|
||||
0x001A, //SUBSTITUTE
|
||||
0x001B, //ESCAPE
|
||||
0x001C, //FILE SEPARATOR
|
||||
0x001D, //GROUP SEPARATOR
|
||||
0x001E, //RECORD SEPARATOR
|
||||
0x001F, //UNIT SEPARATOR
|
||||
0x0020, //SPACE
|
||||
0x0021, //EXCLAMATION MARK
|
||||
0x0022, //QUOTATION MARK
|
||||
0x0023, //NUMBER SIGN
|
||||
0x0024, //DOLLAR SIGN
|
||||
0x0025, //PERCENT SIGN
|
||||
0x0026, //AMPERSAND
|
||||
0x0027, //APOSTROPHE
|
||||
0x0028, //LEFT PARENTHESIS
|
||||
0x0029, //RIGHT PARENTHESIS
|
||||
0x002A, //ASTERISK
|
||||
0x002B, //PLUS SIGN
|
||||
0x002C, //COMMA
|
||||
0x002D, //HYPHEN-MINUS
|
||||
0x002E, //FULL STOP
|
||||
0x002F, //SOLIDUS
|
||||
0x0030, //DIGIT ZERO
|
||||
0x0031, //DIGIT ONE
|
||||
0x0032, //DIGIT TWO
|
||||
0x0033, //DIGIT THREE
|
||||
0x0034, //DIGIT FOUR
|
||||
0x0035, //DIGIT FIVE
|
||||
0x0036, //DIGIT SIX
|
||||
0x0037, //DIGIT SEVEN
|
||||
0x0038, //DIGIT EIGHT
|
||||
0x0039, //DIGIT NINE
|
||||
0x003A, //COLON
|
||||
0x003B, //SEMICOLON
|
||||
0x003C, //LESS-THAN SIGN
|
||||
0x003D, //EQUALS SIGN
|
||||
0x003E, //GREATER-THAN SIGN
|
||||
0x003F, //QUESTION MARK
|
||||
0x0040, //COMMERCIAL AT
|
||||
0x0041, //LATIN CAPITAL LETTER A
|
||||
0x0042, //LATIN CAPITAL LETTER B
|
||||
0x0043, //LATIN CAPITAL LETTER C
|
||||
0x0044, //LATIN CAPITAL LETTER D
|
||||
0x0045, //LATIN CAPITAL LETTER E
|
||||
0x0046, //LATIN CAPITAL LETTER F
|
||||
0x0047, //LATIN CAPITAL LETTER G
|
||||
0x0048, //LATIN CAPITAL LETTER H
|
||||
0x0049, //LATIN CAPITAL LETTER I
|
||||
0x004A, //LATIN CAPITAL LETTER J
|
||||
0x004B, //LATIN CAPITAL LETTER K
|
||||
0x004C, //LATIN CAPITAL LETTER L
|
||||
0x004D, //LATIN CAPITAL LETTER M
|
||||
0x004E, //LATIN CAPITAL LETTER N
|
||||
0x004F, //LATIN CAPITAL LETTER O
|
||||
0x0050, //LATIN CAPITAL LETTER P
|
||||
0x0051, //LATIN CAPITAL LETTER Q
|
||||
0x0052, //LATIN CAPITAL LETTER R
|
||||
0x0053, //LATIN CAPITAL LETTER S
|
||||
0x0054, //LATIN CAPITAL LETTER T
|
||||
0x0055, //LATIN CAPITAL LETTER U
|
||||
0x0056, //LATIN CAPITAL LETTER V
|
||||
0x0057, //LATIN CAPITAL LETTER W
|
||||
0x0058, //LATIN CAPITAL LETTER X
|
||||
0x0059, //LATIN CAPITAL LETTER Y
|
||||
0x005A, //LATIN CAPITAL LETTER Z
|
||||
0x005B, //LEFT SQUARE BRACKET
|
||||
0x005C, //REVERSE SOLIDUS
|
||||
0x005D, //RIGHT SQUARE BRACKET
|
||||
0x005E, //CIRCUMFLEX ACCENT
|
||||
0x005F, //LOW LINE
|
||||
0x0060, //GRAVE ACCENT
|
||||
0x0061, //LATIN SMALL LETTER A
|
||||
0x0062, //LATIN SMALL LETTER B
|
||||
0x0063, //LATIN SMALL LETTER C
|
||||
0x0064, //LATIN SMALL LETTER D
|
||||
0x0065, //LATIN SMALL LETTER E
|
||||
0x0066, //LATIN SMALL LETTER F
|
||||
0x0067, //LATIN SMALL LETTER G
|
||||
0x0068, //LATIN SMALL LETTER H
|
||||
0x0069, //LATIN SMALL LETTER I
|
||||
0x006A, //LATIN SMALL LETTER J
|
||||
0x006B, //LATIN SMALL LETTER K
|
||||
0x006C, //LATIN SMALL LETTER L
|
||||
0x006D, //LATIN SMALL LETTER M
|
||||
0x006E, //LATIN SMALL LETTER N
|
||||
0x006F, //LATIN SMALL LETTER O
|
||||
0x0070, //LATIN SMALL LETTER P
|
||||
0x0071, //LATIN SMALL LETTER Q
|
||||
0x0072, //LATIN SMALL LETTER R
|
||||
0x0073, //LATIN SMALL LETTER S
|
||||
0x0074, //LATIN SMALL LETTER T
|
||||
0x0075, //LATIN SMALL LETTER U
|
||||
0x0076, //LATIN SMALL LETTER V
|
||||
0x0077, //LATIN SMALL LETTER W
|
||||
0x0078, //LATIN SMALL LETTER X
|
||||
0x0079, //LATIN SMALL LETTER Y
|
||||
0x007A, //LATIN SMALL LETTER Z
|
||||
0x007B, //LEFT CURLY BRACKET
|
||||
0x007C, //VERTICAL LINE
|
||||
0x007D, //RIGHT CURLY BRACKET
|
||||
0x007E, //TILDE
|
||||
0x007F, //DELETE
|
||||
0x20AC, //EURO SIGN
|
||||
0xFFFD, //UNDEFINED
|
||||
0x201A, //SINGLE LOW-9 QUOTATION MARK
|
||||
0x0192, //LATIN SMALL LETTER F WITH HOOK
|
||||
0x201E, //DOUBLE LOW-9 QUOTATION MARK
|
||||
0x2026, //HORIZONTAL ELLIPSIS
|
||||
0x2020, //DAGGER
|
||||
0x2021, //DOUBLE DAGGER
|
||||
0x02C6, //MODIFIER LETTER CIRCUMFLEX ACCENT
|
||||
0x2030, //PER MILLE SIGN
|
||||
0x0160, //LATIN CAPITAL LETTER S WITH CARON
|
||||
0x2039, //SINGLE LEFT-POINTING ANGLE QUOTATION MARK
|
||||
0x0152, //LATIN CAPITAL LIGATURE OE
|
||||
0xFFFD, //UNDEFINED
|
||||
0x017D, //LATIN CAPITAL LETTER Z WITH CARON
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0x2018, //LEFT SINGLE QUOTATION MARK
|
||||
0x2019, //RIGHT SINGLE QUOTATION MARK
|
||||
0x201C, //LEFT DOUBLE QUOTATION MARK
|
||||
0x201D, //RIGHT DOUBLE QUOTATION MARK
|
||||
0x2022, //BULLET
|
||||
0x2013, //EN DASH
|
||||
0x2014, //EM DASH
|
||||
0x02DC, //SMALL TILDE
|
||||
0x2122, //TRADE MARK SIGN
|
||||
0x0161, //LATIN SMALL LETTER S WITH CARON
|
||||
0x203A, //SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
|
||||
0x0153, //LATIN SMALL LIGATURE OE
|
||||
0xFFFD, //UNDEFINED
|
||||
0x017E, //LATIN SMALL LETTER Z WITH CARON
|
||||
0x0178, //LATIN CAPITAL LETTER Y WITH DIAERESIS
|
||||
0x00A0, //NO-BREAK SPACE
|
||||
0x00A1, //INVERTED EXCLAMATION MARK
|
||||
0x00A2, //CENT SIGN
|
||||
0x00A3, //POUND SIGN
|
||||
0x00A4, //CURRENCY SIGN
|
||||
0x00A5, //YEN SIGN
|
||||
0x00A6, //BROKEN BAR
|
||||
0x00A7, //SECTION SIGN
|
||||
0x00A8, //DIAERESIS
|
||||
0x00A9, //COPYRIGHT SIGN
|
||||
0x00AA, //FEMININE ORDINAL INDICATOR
|
||||
0x00AB, //LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
|
||||
0x00AC, //NOT SIGN
|
||||
0x00AD, //SOFT HYPHEN
|
||||
0x00AE, //REGISTERED SIGN
|
||||
0x00AF, //MACRON
|
||||
0x00B0, //DEGREE SIGN
|
||||
0x00B1, //PLUS-MINUS SIGN
|
||||
0x00B2, //SUPERSCRIPT TWO
|
||||
0x00B3, //SUPERSCRIPT THREE
|
||||
0x00B4, //ACUTE ACCENT
|
||||
0x00B5, //MICRO SIGN
|
||||
0x00B6, //PILCROW SIGN
|
||||
0x00B7, //MIDDLE DOT
|
||||
0x00B8, //CEDILLA
|
||||
0x00B9, //SUPERSCRIPT ONE
|
||||
0x00BA, //MASCULINE ORDINAL INDICATOR
|
||||
0x00BB, //RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
|
||||
0x00BC, //VULGAR FRACTION ONE QUARTER
|
||||
0x00BD, //VULGAR FRACTION ONE HALF
|
||||
0x00BE, //VULGAR FRACTION THREE QUARTERS
|
||||
0x00BF, //INVERTED QUESTION MARK
|
||||
0x00C0, //LATIN CAPITAL LETTER A WITH GRAVE
|
||||
0x00C1, //LATIN CAPITAL LETTER A WITH ACUTE
|
||||
0x00C2, //LATIN CAPITAL LETTER A WITH CIRCUMFLEX
|
||||
0x00C3, //LATIN CAPITAL LETTER A WITH TILDE
|
||||
0x00C4, //LATIN CAPITAL LETTER A WITH DIAERESIS
|
||||
0x00C5, //LATIN CAPITAL LETTER A WITH RING ABOVE
|
||||
0x00C6, //LATIN CAPITAL LETTER AE
|
||||
0x00C7, //LATIN CAPITAL LETTER C WITH CEDILLA
|
||||
0x00C8, //LATIN CAPITAL LETTER E WITH GRAVE
|
||||
0x00C9, //LATIN CAPITAL LETTER E WITH ACUTE
|
||||
0x00CA, //LATIN CAPITAL LETTER E WITH CIRCUMFLEX
|
||||
0x00CB, //LATIN CAPITAL LETTER E WITH DIAERESIS
|
||||
0x00CC, //LATIN CAPITAL LETTER I WITH GRAVE
|
||||
0x00CD, //LATIN CAPITAL LETTER I WITH ACUTE
|
||||
0x00CE, //LATIN CAPITAL LETTER I WITH CIRCUMFLEX
|
||||
0x00CF, //LATIN CAPITAL LETTER I WITH DIAERESIS
|
||||
0x00D0, //LATIN CAPITAL LETTER ETH
|
||||
0x00D1, //LATIN CAPITAL LETTER N WITH TILDE
|
||||
0x00D2, //LATIN CAPITAL LETTER O WITH GRAVE
|
||||
0x00D3, //LATIN CAPITAL LETTER O WITH ACUTE
|
||||
0x00D4, //LATIN CAPITAL LETTER O WITH CIRCUMFLEX
|
||||
0x00D5, //LATIN CAPITAL LETTER O WITH TILDE
|
||||
0x00D6, //LATIN CAPITAL LETTER O WITH DIAERESIS
|
||||
0x00D7, //MULTIPLICATION SIGN
|
||||
0x00D8, //LATIN CAPITAL LETTER O WITH STROKE
|
||||
0x00D9, //LATIN CAPITAL LETTER U WITH GRAVE
|
||||
0x00DA, //LATIN CAPITAL LETTER U WITH ACUTE
|
||||
0x00DB, //LATIN CAPITAL LETTER U WITH CIRCUMFLEX
|
||||
0x00DC, //LATIN CAPITAL LETTER U WITH DIAERESIS
|
||||
0x00DD, //LATIN CAPITAL LETTER Y WITH ACUTE
|
||||
0x00DE, //LATIN CAPITAL LETTER THORN
|
||||
0x00DF, //LATIN SMALL LETTER SHARP S
|
||||
0x00E0, //LATIN SMALL LETTER A WITH GRAVE
|
||||
0x00E1, //LATIN SMALL LETTER A WITH ACUTE
|
||||
0x00E2, //LATIN SMALL LETTER A WITH CIRCUMFLEX
|
||||
0x00E3, //LATIN SMALL LETTER A WITH TILDE
|
||||
0x00E4, //LATIN SMALL LETTER A WITH DIAERESIS
|
||||
0x00E5, //LATIN SMALL LETTER A WITH RING ABOVE
|
||||
0x00E6, //LATIN SMALL LETTER AE
|
||||
0x00E7, //LATIN SMALL LETTER C WITH CEDILLA
|
||||
0x00E8, //LATIN SMALL LETTER E WITH GRAVE
|
||||
0x00E9, //LATIN SMALL LETTER E WITH ACUTE
|
||||
0x00EA, //LATIN SMALL LETTER E WITH CIRCUMFLEX
|
||||
0x00EB, //LATIN SMALL LETTER E WITH DIAERESIS
|
||||
0x00EC, //LATIN SMALL LETTER I WITH GRAVE
|
||||
0x00ED, //LATIN SMALL LETTER I WITH ACUTE
|
||||
0x00EE, //LATIN SMALL LETTER I WITH CIRCUMFLEX
|
||||
0x00EF, //LATIN SMALL LETTER I WITH DIAERESIS
|
||||
0x00F0, //LATIN SMALL LETTER ETH
|
||||
0x00F1, //LATIN SMALL LETTER N WITH TILDE
|
||||
0x00F2, //LATIN SMALL LETTER O WITH GRAVE
|
||||
0x00F3, //LATIN SMALL LETTER O WITH ACUTE
|
||||
0x00F4, //LATIN SMALL LETTER O WITH CIRCUMFLEX
|
||||
0x00F5, //LATIN SMALL LETTER O WITH TILDE
|
||||
0x00F6, //LATIN SMALL LETTER O WITH DIAERESIS
|
||||
0x00F7, //DIVISION SIGN
|
||||
0x00F8, //LATIN SMALL LETTER O WITH STROKE
|
||||
0x00F9, //LATIN SMALL LETTER U WITH GRAVE
|
||||
0x00FA, //LATIN SMALL LETTER U WITH ACUTE
|
||||
0x00FB, //LATIN SMALL LETTER U WITH CIRCUMFLEX
|
||||
0x00FC, //LATIN SMALL LETTER U WITH DIAERESIS
|
||||
0x00FD, //LATIN SMALL LETTER Y WITH ACUTE
|
||||
0x00FE, //LATIN SMALL LETTER THORN
|
||||
0x00FF, //LATIN SMALL LETTER Y WITH DIAERESIS
|
||||
},
|
||||
}
|
|
@ -1,262 +0,0 @@
|
|||
package cp
|
||||
|
||||
var cp1253 *charsetMap = &charsetMap{
|
||||
sb: [256]rune{
|
||||
0x0000, //NULL
|
||||
0x0001, //START OF HEADING
|
||||
0x0002, //START OF TEXT
|
||||
0x0003, //END OF TEXT
|
||||
0x0004, //END OF TRANSMISSION
|
||||
0x0005, //ENQUIRY
|
||||
0x0006, //ACKNOWLEDGE
|
||||
0x0007, //BELL
|
||||
0x0008, //BACKSPACE
|
||||
0x0009, //HORIZONTAL TABULATION
|
||||
0x000A, //LINE FEED
|
||||
0x000B, //VERTICAL TABULATION
|
||||
0x000C, //FORM FEED
|
||||
0x000D, //CARRIAGE RETURN
|
||||
0x000E, //SHIFT OUT
|
||||
0x000F, //SHIFT IN
|
||||
0x0010, //DATA LINK ESCAPE
|
||||
0x0011, //DEVICE CONTROL ONE
|
||||
0x0012, //DEVICE CONTROL TWO
|
||||
0x0013, //DEVICE CONTROL THREE
|
||||
0x0014, //DEVICE CONTROL FOUR
|
||||
0x0015, //NEGATIVE ACKNOWLEDGE
|
||||
0x0016, //SYNCHRONOUS IDLE
|
||||
0x0017, //END OF TRANSMISSION BLOCK
|
||||
0x0018, //CANCEL
|
||||
0x0019, //END OF MEDIUM
|
||||
0x001A, //SUBSTITUTE
|
||||
0x001B, //ESCAPE
|
||||
0x001C, //FILE SEPARATOR
|
||||
0x001D, //GROUP SEPARATOR
|
||||
0x001E, //RECORD SEPARATOR
|
||||
0x001F, //UNIT SEPARATOR
|
||||
0x0020, //SPACE
|
||||
0x0021, //EXCLAMATION MARK
|
||||
0x0022, //QUOTATION MARK
|
||||
0x0023, //NUMBER SIGN
|
||||
0x0024, //DOLLAR SIGN
|
||||
0x0025, //PERCENT SIGN
|
||||
0x0026, //AMPERSAND
|
||||
0x0027, //APOSTROPHE
|
||||
0x0028, //LEFT PARENTHESIS
|
||||
0x0029, //RIGHT PARENTHESIS
|
||||
0x002A, //ASTERISK
|
||||
0x002B, //PLUS SIGN
|
||||
0x002C, //COMMA
|
||||
0x002D, //HYPHEN-MINUS
|
||||
0x002E, //FULL STOP
|
||||
0x002F, //SOLIDUS
|
||||
0x0030, //DIGIT ZERO
|
||||
0x0031, //DIGIT ONE
|
||||
0x0032, //DIGIT TWO
|
||||
0x0033, //DIGIT THREE
|
||||
0x0034, //DIGIT FOUR
|
||||
0x0035, //DIGIT FIVE
|
||||
0x0036, //DIGIT SIX
|
||||
0x0037, //DIGIT SEVEN
|
||||
0x0038, //DIGIT EIGHT
|
||||
0x0039, //DIGIT NINE
|
||||
0x003A, //COLON
|
||||
0x003B, //SEMICOLON
|
||||
0x003C, //LESS-THAN SIGN
|
||||
0x003D, //EQUALS SIGN
|
||||
0x003E, //GREATER-THAN SIGN
|
||||
0x003F, //QUESTION MARK
|
||||
0x0040, //COMMERCIAL AT
|
||||
0x0041, //LATIN CAPITAL LETTER A
|
||||
0x0042, //LATIN CAPITAL LETTER B
|
||||
0x0043, //LATIN CAPITAL LETTER C
|
||||
0x0044, //LATIN CAPITAL LETTER D
|
||||
0x0045, //LATIN CAPITAL LETTER E
|
||||
0x0046, //LATIN CAPITAL LETTER F
|
||||
0x0047, //LATIN CAPITAL LETTER G
|
||||
0x0048, //LATIN CAPITAL LETTER H
|
||||
0x0049, //LATIN CAPITAL LETTER I
|
||||
0x004A, //LATIN CAPITAL LETTER J
|
||||
0x004B, //LATIN CAPITAL LETTER K
|
||||
0x004C, //LATIN CAPITAL LETTER L
|
||||
0x004D, //LATIN CAPITAL LETTER M
|
||||
0x004E, //LATIN CAPITAL LETTER N
|
||||
0x004F, //LATIN CAPITAL LETTER O
|
||||
0x0050, //LATIN CAPITAL LETTER P
|
||||
0x0051, //LATIN CAPITAL LETTER Q
|
||||
0x0052, //LATIN CAPITAL LETTER R
|
||||
0x0053, //LATIN CAPITAL LETTER S
|
||||
0x0054, //LATIN CAPITAL LETTER T
|
||||
0x0055, //LATIN CAPITAL LETTER U
|
||||
0x0056, //LATIN CAPITAL LETTER V
|
||||
0x0057, //LATIN CAPITAL LETTER W
|
||||
0x0058, //LATIN CAPITAL LETTER X
|
||||
0x0059, //LATIN CAPITAL LETTER Y
|
||||
0x005A, //LATIN CAPITAL LETTER Z
|
||||
0x005B, //LEFT SQUARE BRACKET
|
||||
0x005C, //REVERSE SOLIDUS
|
||||
0x005D, //RIGHT SQUARE BRACKET
|
||||
0x005E, //CIRCUMFLEX ACCENT
|
||||
0x005F, //LOW LINE
|
||||
0x0060, //GRAVE ACCENT
|
||||
0x0061, //LATIN SMALL LETTER A
|
||||
0x0062, //LATIN SMALL LETTER B
|
||||
0x0063, //LATIN SMALL LETTER C
|
||||
0x0064, //LATIN SMALL LETTER D
|
||||
0x0065, //LATIN SMALL LETTER E
|
||||
0x0066, //LATIN SMALL LETTER F
|
||||
0x0067, //LATIN SMALL LETTER G
|
||||
0x0068, //LATIN SMALL LETTER H
|
||||
0x0069, //LATIN SMALL LETTER I
|
||||
0x006A, //LATIN SMALL LETTER J
|
||||
0x006B, //LATIN SMALL LETTER K
|
||||
0x006C, //LATIN SMALL LETTER L
|
||||
0x006D, //LATIN SMALL LETTER M
|
||||
0x006E, //LATIN SMALL LETTER N
|
||||
0x006F, //LATIN SMALL LETTER O
|
||||
0x0070, //LATIN SMALL LETTER P
|
||||
0x0071, //LATIN SMALL LETTER Q
|
||||
0x0072, //LATIN SMALL LETTER R
|
||||
0x0073, //LATIN SMALL LETTER S
|
||||
0x0074, //LATIN SMALL LETTER T
|
||||
0x0075, //LATIN SMALL LETTER U
|
||||
0x0076, //LATIN SMALL LETTER V
|
||||
0x0077, //LATIN SMALL LETTER W
|
||||
0x0078, //LATIN SMALL LETTER X
|
||||
0x0079, //LATIN SMALL LETTER Y
|
||||
0x007A, //LATIN SMALL LETTER Z
|
||||
0x007B, //LEFT CURLY BRACKET
|
||||
0x007C, //VERTICAL LINE
|
||||
0x007D, //RIGHT CURLY BRACKET
|
||||
0x007E, //TILDE
|
||||
0x007F, //DELETE
|
||||
0x20AC, //EURO SIGN
|
||||
0xFFFD, //UNDEFINED
|
||||
0x201A, //SINGLE LOW-9 QUOTATION MARK
|
||||
0x0192, //LATIN SMALL LETTER F WITH HOOK
|
||||
0x201E, //DOUBLE LOW-9 QUOTATION MARK
|
||||
0x2026, //HORIZONTAL ELLIPSIS
|
||||
0x2020, //DAGGER
|
||||
0x2021, //DOUBLE DAGGER
|
||||
0xFFFD, //UNDEFINED
|
||||
0x2030, //PER MILLE SIGN
|
||||
0xFFFD, //UNDEFINED
|
||||
0x2039, //SINGLE LEFT-POINTING ANGLE QUOTATION MARK
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0x2018, //LEFT SINGLE QUOTATION MARK
|
||||
0x2019, //RIGHT SINGLE QUOTATION MARK
|
||||
0x201C, //LEFT DOUBLE QUOTATION MARK
|
||||
0x201D, //RIGHT DOUBLE QUOTATION MARK
|
||||
0x2022, //BULLET
|
||||
0x2013, //EN DASH
|
||||
0x2014, //EM DASH
|
||||
0xFFFD, //UNDEFINED
|
||||
0x2122, //TRADE MARK SIGN
|
||||
0xFFFD, //UNDEFINED
|
||||
0x203A, //SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0x00A0, //NO-BREAK SPACE
|
||||
0x0385, //GREEK DIALYTIKA TONOS
|
||||
0x0386, //GREEK CAPITAL LETTER ALPHA WITH TONOS
|
||||
0x00A3, //POUND SIGN
|
||||
0x00A4, //CURRENCY SIGN
|
||||
0x00A5, //YEN SIGN
|
||||
0x00A6, //BROKEN BAR
|
||||
0x00A7, //SECTION SIGN
|
||||
0x00A8, //DIAERESIS
|
||||
0x00A9, //COPYRIGHT SIGN
|
||||
0xFFFD, //UNDEFINED
|
||||
0x00AB, //LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
|
||||
0x00AC, //NOT SIGN
|
||||
0x00AD, //SOFT HYPHEN
|
||||
0x00AE, //REGISTERED SIGN
|
||||
0x2015, //HORIZONTAL BAR
|
||||
0x00B0, //DEGREE SIGN
|
||||
0x00B1, //PLUS-MINUS SIGN
|
||||
0x00B2, //SUPERSCRIPT TWO
|
||||
0x00B3, //SUPERSCRIPT THREE
|
||||
0x0384, //GREEK TONOS
|
||||
0x00B5, //MICRO SIGN
|
||||
0x00B6, //PILCROW SIGN
|
||||
0x00B7, //MIDDLE DOT
|
||||
0x0388, //GREEK CAPITAL LETTER EPSILON WITH TONOS
|
||||
0x0389, //GREEK CAPITAL LETTER ETA WITH TONOS
|
||||
0x038A, //GREEK CAPITAL LETTER IOTA WITH TONOS
|
||||
0x00BB, //RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
|
||||
0x038C, //GREEK CAPITAL LETTER OMICRON WITH TONOS
|
||||
0x00BD, //VULGAR FRACTION ONE HALF
|
||||
0x038E, //GREEK CAPITAL LETTER UPSILON WITH TONOS
|
||||
0x038F, //GREEK CAPITAL LETTER OMEGA WITH TONOS
|
||||
0x0390, //GREEK SMALL LETTER IOTA WITH DIALYTIKA AND TONOS
|
||||
0x0391, //GREEK CAPITAL LETTER ALPHA
|
||||
0x0392, //GREEK CAPITAL LETTER BETA
|
||||
0x0393, //GREEK CAPITAL LETTER GAMMA
|
||||
0x0394, //GREEK CAPITAL LETTER DELTA
|
||||
0x0395, //GREEK CAPITAL LETTER EPSILON
|
||||
0x0396, //GREEK CAPITAL LETTER ZETA
|
||||
0x0397, //GREEK CAPITAL LETTER ETA
|
||||
0x0398, //GREEK CAPITAL LETTER THETA
|
||||
0x0399, //GREEK CAPITAL LETTER IOTA
|
||||
0x039A, //GREEK CAPITAL LETTER KAPPA
|
||||
0x039B, //GREEK CAPITAL LETTER LAMDA
|
||||
0x039C, //GREEK CAPITAL LETTER MU
|
||||
0x039D, //GREEK CAPITAL LETTER NU
|
||||
0x039E, //GREEK CAPITAL LETTER XI
|
||||
0x039F, //GREEK CAPITAL LETTER OMICRON
|
||||
0x03A0, //GREEK CAPITAL LETTER PI
|
||||
0x03A1, //GREEK CAPITAL LETTER RHO
|
||||
0xFFFD, //UNDEFINED
|
||||
0x03A3, //GREEK CAPITAL LETTER SIGMA
|
||||
0x03A4, //GREEK CAPITAL LETTER TAU
|
||||
0x03A5, //GREEK CAPITAL LETTER UPSILON
|
||||
0x03A6, //GREEK CAPITAL LETTER PHI
|
||||
0x03A7, //GREEK CAPITAL LETTER CHI
|
||||
0x03A8, //GREEK CAPITAL LETTER PSI
|
||||
0x03A9, //GREEK CAPITAL LETTER OMEGA
|
||||
0x03AA, //GREEK CAPITAL LETTER IOTA WITH DIALYTIKA
|
||||
0x03AB, //GREEK CAPITAL LETTER UPSILON WITH DIALYTIKA
|
||||
0x03AC, //GREEK SMALL LETTER ALPHA WITH TONOS
|
||||
0x03AD, //GREEK SMALL LETTER EPSILON WITH TONOS
|
||||
0x03AE, //GREEK SMALL LETTER ETA WITH TONOS
|
||||
0x03AF, //GREEK SMALL LETTER IOTA WITH TONOS
|
||||
0x03B0, //GREEK SMALL LETTER UPSILON WITH DIALYTIKA AND TONOS
|
||||
0x03B1, //GREEK SMALL LETTER ALPHA
|
||||
0x03B2, //GREEK SMALL LETTER BETA
|
||||
0x03B3, //GREEK SMALL LETTER GAMMA
|
||||
0x03B4, //GREEK SMALL LETTER DELTA
|
||||
0x03B5, //GREEK SMALL LETTER EPSILON
|
||||
0x03B6, //GREEK SMALL LETTER ZETA
|
||||
0x03B7, //GREEK SMALL LETTER ETA
|
||||
0x03B8, //GREEK SMALL LETTER THETA
|
||||
0x03B9, //GREEK SMALL LETTER IOTA
|
||||
0x03BA, //GREEK SMALL LETTER KAPPA
|
||||
0x03BB, //GREEK SMALL LETTER LAMDA
|
||||
0x03BC, //GREEK SMALL LETTER MU
|
||||
0x03BD, //GREEK SMALL LETTER NU
|
||||
0x03BE, //GREEK SMALL LETTER XI
|
||||
0x03BF, //GREEK SMALL LETTER OMICRON
|
||||
0x03C0, //GREEK SMALL LETTER PI
|
||||
0x03C1, //GREEK SMALL LETTER RHO
|
||||
0x03C2, //GREEK SMALL LETTER FINAL SIGMA
|
||||
0x03C3, //GREEK SMALL LETTER SIGMA
|
||||
0x03C4, //GREEK SMALL LETTER TAU
|
||||
0x03C5, //GREEK SMALL LETTER UPSILON
|
||||
0x03C6, //GREEK SMALL LETTER PHI
|
||||
0x03C7, //GREEK SMALL LETTER CHI
|
||||
0x03C8, //GREEK SMALL LETTER PSI
|
||||
0x03C9, //GREEK SMALL LETTER OMEGA
|
||||
0x03CA, //GREEK SMALL LETTER IOTA WITH DIALYTIKA
|
||||
0x03CB, //GREEK SMALL LETTER UPSILON WITH DIALYTIKA
|
||||
0x03CC, //GREEK SMALL LETTER OMICRON WITH TONOS
|
||||
0x03CD, //GREEK SMALL LETTER UPSILON WITH TONOS
|
||||
0x03CE, //GREEK SMALL LETTER OMEGA WITH TONOS
|
||||
0xFFFD, //UNDEFINED
|
||||
},
|
||||
}
|
|
@ -1,262 +0,0 @@
|
|||
package cp
|
||||
|
||||
var cp1254 *charsetMap = &charsetMap{
|
||||
sb: [256]rune{
|
||||
0x0000, //NULL
|
||||
0x0001, //START OF HEADING
|
||||
0x0002, //START OF TEXT
|
||||
0x0003, //END OF TEXT
|
||||
0x0004, //END OF TRANSMISSION
|
||||
0x0005, //ENQUIRY
|
||||
0x0006, //ACKNOWLEDGE
|
||||
0x0007, //BELL
|
||||
0x0008, //BACKSPACE
|
||||
0x0009, //HORIZONTAL TABULATION
|
||||
0x000A, //LINE FEED
|
||||
0x000B, //VERTICAL TABULATION
|
||||
0x000C, //FORM FEED
|
||||
0x000D, //CARRIAGE RETURN
|
||||
0x000E, //SHIFT OUT
|
||||
0x000F, //SHIFT IN
|
||||
0x0010, //DATA LINK ESCAPE
|
||||
0x0011, //DEVICE CONTROL ONE
|
||||
0x0012, //DEVICE CONTROL TWO
|
||||
0x0013, //DEVICE CONTROL THREE
|
||||
0x0014, //DEVICE CONTROL FOUR
|
||||
0x0015, //NEGATIVE ACKNOWLEDGE
|
||||
0x0016, //SYNCHRONOUS IDLE
|
||||
0x0017, //END OF TRANSMISSION BLOCK
|
||||
0x0018, //CANCEL
|
||||
0x0019, //END OF MEDIUM
|
||||
0x001A, //SUBSTITUTE
|
||||
0x001B, //ESCAPE
|
||||
0x001C, //FILE SEPARATOR
|
||||
0x001D, //GROUP SEPARATOR
|
||||
0x001E, //RECORD SEPARATOR
|
||||
0x001F, //UNIT SEPARATOR
|
||||
0x0020, //SPACE
|
||||
0x0021, //EXCLAMATION MARK
|
||||
0x0022, //QUOTATION MARK
|
||||
0x0023, //NUMBER SIGN
|
||||
0x0024, //DOLLAR SIGN
|
||||
0x0025, //PERCENT SIGN
|
||||
0x0026, //AMPERSAND
|
||||
0x0027, //APOSTROPHE
|
||||
0x0028, //LEFT PARENTHESIS
|
||||
0x0029, //RIGHT PARENTHESIS
|
||||
0x002A, //ASTERISK
|
||||
0x002B, //PLUS SIGN
|
||||
0x002C, //COMMA
|
||||
0x002D, //HYPHEN-MINUS
|
||||
0x002E, //FULL STOP
|
||||
0x002F, //SOLIDUS
|
||||
0x0030, //DIGIT ZERO
|
||||
0x0031, //DIGIT ONE
|
||||
0x0032, //DIGIT TWO
|
||||
0x0033, //DIGIT THREE
|
||||
0x0034, //DIGIT FOUR
|
||||
0x0035, //DIGIT FIVE
|
||||
0x0036, //DIGIT SIX
|
||||
0x0037, //DIGIT SEVEN
|
||||
0x0038, //DIGIT EIGHT
|
||||
0x0039, //DIGIT NINE
|
||||
0x003A, //COLON
|
||||
0x003B, //SEMICOLON
|
||||
0x003C, //LESS-THAN SIGN
|
||||
0x003D, //EQUALS SIGN
|
||||
0x003E, //GREATER-THAN SIGN
|
||||
0x003F, //QUESTION MARK
|
||||
0x0040, //COMMERCIAL AT
|
||||
0x0041, //LATIN CAPITAL LETTER A
|
||||
0x0042, //LATIN CAPITAL LETTER B
|
||||
0x0043, //LATIN CAPITAL LETTER C
|
||||
0x0044, //LATIN CAPITAL LETTER D
|
||||
0x0045, //LATIN CAPITAL LETTER E
|
||||
0x0046, //LATIN CAPITAL LETTER F
|
||||
0x0047, //LATIN CAPITAL LETTER G
|
||||
0x0048, //LATIN CAPITAL LETTER H
|
||||
0x0049, //LATIN CAPITAL LETTER I
|
||||
0x004A, //LATIN CAPITAL LETTER J
|
||||
0x004B, //LATIN CAPITAL LETTER K
|
||||
0x004C, //LATIN CAPITAL LETTER L
|
||||
0x004D, //LATIN CAPITAL LETTER M
|
||||
0x004E, //LATIN CAPITAL LETTER N
|
||||
0x004F, //LATIN CAPITAL LETTER O
|
||||
0x0050, //LATIN CAPITAL LETTER P
|
||||
0x0051, //LATIN CAPITAL LETTER Q
|
||||
0x0052, //LATIN CAPITAL LETTER R
|
||||
0x0053, //LATIN CAPITAL LETTER S
|
||||
0x0054, //LATIN CAPITAL LETTER T
|
||||
0x0055, //LATIN CAPITAL LETTER U
|
||||
0x0056, //LATIN CAPITAL LETTER V
|
||||
0x0057, //LATIN CAPITAL LETTER W
|
||||
0x0058, //LATIN CAPITAL LETTER X
|
||||
0x0059, //LATIN CAPITAL LETTER Y
|
||||
0x005A, //LATIN CAPITAL LETTER Z
|
||||
0x005B, //LEFT SQUARE BRACKET
|
||||
0x005C, //REVERSE SOLIDUS
|
||||
0x005D, //RIGHT SQUARE BRACKET
|
||||
0x005E, //CIRCUMFLEX ACCENT
|
||||
0x005F, //LOW LINE
|
||||
0x0060, //GRAVE ACCENT
|
||||
0x0061, //LATIN SMALL LETTER A
|
||||
0x0062, //LATIN SMALL LETTER B
|
||||
0x0063, //LATIN SMALL LETTER C
|
||||
0x0064, //LATIN SMALL LETTER D
|
||||
0x0065, //LATIN SMALL LETTER E
|
||||
0x0066, //LATIN SMALL LETTER F
|
||||
0x0067, //LATIN SMALL LETTER G
|
||||
0x0068, //LATIN SMALL LETTER H
|
||||
0x0069, //LATIN SMALL LETTER I
|
||||
0x006A, //LATIN SMALL LETTER J
|
||||
0x006B, //LATIN SMALL LETTER K
|
||||
0x006C, //LATIN SMALL LETTER L
|
||||
0x006D, //LATIN SMALL LETTER M
|
||||
0x006E, //LATIN SMALL LETTER N
|
||||
0x006F, //LATIN SMALL LETTER O
|
||||
0x0070, //LATIN SMALL LETTER P
|
||||
0x0071, //LATIN SMALL LETTER Q
|
||||
0x0072, //LATIN SMALL LETTER R
|
||||
0x0073, //LATIN SMALL LETTER S
|
||||
0x0074, //LATIN SMALL LETTER T
|
||||
0x0075, //LATIN SMALL LETTER U
|
||||
0x0076, //LATIN SMALL LETTER V
|
||||
0x0077, //LATIN SMALL LETTER W
|
||||
0x0078, //LATIN SMALL LETTER X
|
||||
0x0079, //LATIN SMALL LETTER Y
|
||||
0x007A, //LATIN SMALL LETTER Z
|
||||
0x007B, //LEFT CURLY BRACKET
|
||||
0x007C, //VERTICAL LINE
|
||||
0x007D, //RIGHT CURLY BRACKET
|
||||
0x007E, //TILDE
|
||||
0x007F, //DELETE
|
||||
0x20AC, //EURO SIGN
|
||||
0xFFFD, //UNDEFINED
|
||||
0x201A, //SINGLE LOW-9 QUOTATION MARK
|
||||
0x0192, //LATIN SMALL LETTER F WITH HOOK
|
||||
0x201E, //DOUBLE LOW-9 QUOTATION MARK
|
||||
0x2026, //HORIZONTAL ELLIPSIS
|
||||
0x2020, //DAGGER
|
||||
0x2021, //DOUBLE DAGGER
|
||||
0x02C6, //MODIFIER LETTER CIRCUMFLEX ACCENT
|
||||
0x2030, //PER MILLE SIGN
|
||||
0x0160, //LATIN CAPITAL LETTER S WITH CARON
|
||||
0x2039, //SINGLE LEFT-POINTING ANGLE QUOTATION MARK
|
||||
0x0152, //LATIN CAPITAL LIGATURE OE
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0x2018, //LEFT SINGLE QUOTATION MARK
|
||||
0x2019, //RIGHT SINGLE QUOTATION MARK
|
||||
0x201C, //LEFT DOUBLE QUOTATION MARK
|
||||
0x201D, //RIGHT DOUBLE QUOTATION MARK
|
||||
0x2022, //BULLET
|
||||
0x2013, //EN DASH
|
||||
0x2014, //EM DASH
|
||||
0x02DC, //SMALL TILDE
|
||||
0x2122, //TRADE MARK SIGN
|
||||
0x0161, //LATIN SMALL LETTER S WITH CARON
|
||||
0x203A, //SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
|
||||
0x0153, //LATIN SMALL LIGATURE OE
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0x0178, //LATIN CAPITAL LETTER Y WITH DIAERESIS
|
||||
0x00A0, //NO-BREAK SPACE
|
||||
0x00A1, //INVERTED EXCLAMATION MARK
|
||||
0x00A2, //CENT SIGN
|
||||
0x00A3, //POUND SIGN
|
||||
0x00A4, //CURRENCY SIGN
|
||||
0x00A5, //YEN SIGN
|
||||
0x00A6, //BROKEN BAR
|
||||
0x00A7, //SECTION SIGN
|
||||
0x00A8, //DIAERESIS
|
||||
0x00A9, //COPYRIGHT SIGN
|
||||
0x00AA, //FEMININE ORDINAL INDICATOR
|
||||
0x00AB, //LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
|
||||
0x00AC, //NOT SIGN
|
||||
0x00AD, //SOFT HYPHEN
|
||||
0x00AE, //REGISTERED SIGN
|
||||
0x00AF, //MACRON
|
||||
0x00B0, //DEGREE SIGN
|
||||
0x00B1, //PLUS-MINUS SIGN
|
||||
0x00B2, //SUPERSCRIPT TWO
|
||||
0x00B3, //SUPERSCRIPT THREE
|
||||
0x00B4, //ACUTE ACCENT
|
||||
0x00B5, //MICRO SIGN
|
||||
0x00B6, //PILCROW SIGN
|
||||
0x00B7, //MIDDLE DOT
|
||||
0x00B8, //CEDILLA
|
||||
0x00B9, //SUPERSCRIPT ONE
|
||||
0x00BA, //MASCULINE ORDINAL INDICATOR
|
||||
0x00BB, //RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
|
||||
0x00BC, //VULGAR FRACTION ONE QUARTER
|
||||
0x00BD, //VULGAR FRACTION ONE HALF
|
||||
0x00BE, //VULGAR FRACTION THREE QUARTERS
|
||||
0x00BF, //INVERTED QUESTION MARK
|
||||
0x00C0, //LATIN CAPITAL LETTER A WITH GRAVE
|
||||
0x00C1, //LATIN CAPITAL LETTER A WITH ACUTE
|
||||
0x00C2, //LATIN CAPITAL LETTER A WITH CIRCUMFLEX
|
||||
0x00C3, //LATIN CAPITAL LETTER A WITH TILDE
|
||||
0x00C4, //LATIN CAPITAL LETTER A WITH DIAERESIS
|
||||
0x00C5, //LATIN CAPITAL LETTER A WITH RING ABOVE
|
||||
0x00C6, //LATIN CAPITAL LETTER AE
|
||||
0x00C7, //LATIN CAPITAL LETTER C WITH CEDILLA
|
||||
0x00C8, //LATIN CAPITAL LETTER E WITH GRAVE
|
||||
0x00C9, //LATIN CAPITAL LETTER E WITH ACUTE
|
||||
0x00CA, //LATIN CAPITAL LETTER E WITH CIRCUMFLEX
|
||||
0x00CB, //LATIN CAPITAL LETTER E WITH DIAERESIS
|
||||
0x00CC, //LATIN CAPITAL LETTER I WITH GRAVE
|
||||
0x00CD, //LATIN CAPITAL LETTER I WITH ACUTE
|
||||
0x00CE, //LATIN CAPITAL LETTER I WITH CIRCUMFLEX
|
||||
0x00CF, //LATIN CAPITAL LETTER I WITH DIAERESIS
|
||||
0x011E, //LATIN CAPITAL LETTER G WITH BREVE
|
||||
0x00D1, //LATIN CAPITAL LETTER N WITH TILDE
|
||||
0x00D2, //LATIN CAPITAL LETTER O WITH GRAVE
|
||||
0x00D3, //LATIN CAPITAL LETTER O WITH ACUTE
|
||||
0x00D4, //LATIN CAPITAL LETTER O WITH CIRCUMFLEX
|
||||
0x00D5, //LATIN CAPITAL LETTER O WITH TILDE
|
||||
0x00D6, //LATIN CAPITAL LETTER O WITH DIAERESIS
|
||||
0x00D7, //MULTIPLICATION SIGN
|
||||
0x00D8, //LATIN CAPITAL LETTER O WITH STROKE
|
||||
0x00D9, //LATIN CAPITAL LETTER U WITH GRAVE
|
||||
0x00DA, //LATIN CAPITAL LETTER U WITH ACUTE
|
||||
0x00DB, //LATIN CAPITAL LETTER U WITH CIRCUMFLEX
|
||||
0x00DC, //LATIN CAPITAL LETTER U WITH DIAERESIS
|
||||
0x0130, //LATIN CAPITAL LETTER I WITH DOT ABOVE
|
||||
0x015E, //LATIN CAPITAL LETTER S WITH CEDILLA
|
||||
0x00DF, //LATIN SMALL LETTER SHARP S
|
||||
0x00E0, //LATIN SMALL LETTER A WITH GRAVE
|
||||
0x00E1, //LATIN SMALL LETTER A WITH ACUTE
|
||||
0x00E2, //LATIN SMALL LETTER A WITH CIRCUMFLEX
|
||||
0x00E3, //LATIN SMALL LETTER A WITH TILDE
|
||||
0x00E4, //LATIN SMALL LETTER A WITH DIAERESIS
|
||||
0x00E5, //LATIN SMALL LETTER A WITH RING ABOVE
|
||||
0x00E6, //LATIN SMALL LETTER AE
|
||||
0x00E7, //LATIN SMALL LETTER C WITH CEDILLA
|
||||
0x00E8, //LATIN SMALL LETTER E WITH GRAVE
|
||||
0x00E9, //LATIN SMALL LETTER E WITH ACUTE
|
||||
0x00EA, //LATIN SMALL LETTER E WITH CIRCUMFLEX
|
||||
0x00EB, //LATIN SMALL LETTER E WITH DIAERESIS
|
||||
0x00EC, //LATIN SMALL LETTER I WITH GRAVE
|
||||
0x00ED, //LATIN SMALL LETTER I WITH ACUTE
|
||||
0x00EE, //LATIN SMALL LETTER I WITH CIRCUMFLEX
|
||||
0x00EF, //LATIN SMALL LETTER I WITH DIAERESIS
|
||||
0x011F, //LATIN SMALL LETTER G WITH BREVE
|
||||
0x00F1, //LATIN SMALL LETTER N WITH TILDE
|
||||
0x00F2, //LATIN SMALL LETTER O WITH GRAVE
|
||||
0x00F3, //LATIN SMALL LETTER O WITH ACUTE
|
||||
0x00F4, //LATIN SMALL LETTER O WITH CIRCUMFLEX
|
||||
0x00F5, //LATIN SMALL LETTER O WITH TILDE
|
||||
0x00F6, //LATIN SMALL LETTER O WITH DIAERESIS
|
||||
0x00F7, //DIVISION SIGN
|
||||
0x00F8, //LATIN SMALL LETTER O WITH STROKE
|
||||
0x00F9, //LATIN SMALL LETTER U WITH GRAVE
|
||||
0x00FA, //LATIN SMALL LETTER U WITH ACUTE
|
||||
0x00FB, //LATIN SMALL LETTER U WITH CIRCUMFLEX
|
||||
0x00FC, //LATIN SMALL LETTER U WITH DIAERESIS
|
||||
0x0131, //LATIN SMALL LETTER DOTLESS I
|
||||
0x015F, //LATIN SMALL LETTER S WITH CEDILLA
|
||||
0x00FF, //LATIN SMALL LETTER Y WITH DIAERESIS
|
||||
},
|
||||
}
|
|
@ -1,262 +0,0 @@
|
|||
package cp
|
||||
|
||||
var cp1255 *charsetMap = &charsetMap{
|
||||
sb: [256]rune{
|
||||
0x0000, //NULL
|
||||
0x0001, //START OF HEADING
|
||||
0x0002, //START OF TEXT
|
||||
0x0003, //END OF TEXT
|
||||
0x0004, //END OF TRANSMISSION
|
||||
0x0005, //ENQUIRY
|
||||
0x0006, //ACKNOWLEDGE
|
||||
0x0007, //BELL
|
||||
0x0008, //BACKSPACE
|
||||
0x0009, //HORIZONTAL TABULATION
|
||||
0x000A, //LINE FEED
|
||||
0x000B, //VERTICAL TABULATION
|
||||
0x000C, //FORM FEED
|
||||
0x000D, //CARRIAGE RETURN
|
||||
0x000E, //SHIFT OUT
|
||||
0x000F, //SHIFT IN
|
||||
0x0010, //DATA LINK ESCAPE
|
||||
0x0011, //DEVICE CONTROL ONE
|
||||
0x0012, //DEVICE CONTROL TWO
|
||||
0x0013, //DEVICE CONTROL THREE
|
||||
0x0014, //DEVICE CONTROL FOUR
|
||||
0x0015, //NEGATIVE ACKNOWLEDGE
|
||||
0x0016, //SYNCHRONOUS IDLE
|
||||
0x0017, //END OF TRANSMISSION BLOCK
|
||||
0x0018, //CANCEL
|
||||
0x0019, //END OF MEDIUM
|
||||
0x001A, //SUBSTITUTE
|
||||
0x001B, //ESCAPE
|
||||
0x001C, //FILE SEPARATOR
|
||||
0x001D, //GROUP SEPARATOR
|
||||
0x001E, //RECORD SEPARATOR
|
||||
0x001F, //UNIT SEPARATOR
|
||||
0x0020, //SPACE
|
||||
0x0021, //EXCLAMATION MARK
|
||||
0x0022, //QUOTATION MARK
|
||||
0x0023, //NUMBER SIGN
|
||||
0x0024, //DOLLAR SIGN
|
||||
0x0025, //PERCENT SIGN
|
||||
0x0026, //AMPERSAND
|
||||
0x0027, //APOSTROPHE
|
||||
0x0028, //LEFT PARENTHESIS
|
||||
0x0029, //RIGHT PARENTHESIS
|
||||
0x002A, //ASTERISK
|
||||
0x002B, //PLUS SIGN
|
||||
0x002C, //COMMA
|
||||
0x002D, //HYPHEN-MINUS
|
||||
0x002E, //FULL STOP
|
||||
0x002F, //SOLIDUS
|
||||
0x0030, //DIGIT ZERO
|
||||
0x0031, //DIGIT ONE
|
||||
0x0032, //DIGIT TWO
|
||||
0x0033, //DIGIT THREE
|
||||
0x0034, //DIGIT FOUR
|
||||
0x0035, //DIGIT FIVE
|
||||
0x0036, //DIGIT SIX
|
||||
0x0037, //DIGIT SEVEN
|
||||
0x0038, //DIGIT EIGHT
|
||||
0x0039, //DIGIT NINE
|
||||
0x003A, //COLON
|
||||
0x003B, //SEMICOLON
|
||||
0x003C, //LESS-THAN SIGN
|
||||
0x003D, //EQUALS SIGN
|
||||
0x003E, //GREATER-THAN SIGN
|
||||
0x003F, //QUESTION MARK
|
||||
0x0040, //COMMERCIAL AT
|
||||
0x0041, //LATIN CAPITAL LETTER A
|
||||
0x0042, //LATIN CAPITAL LETTER B
|
||||
0x0043, //LATIN CAPITAL LETTER C
|
||||
0x0044, //LATIN CAPITAL LETTER D
|
||||
0x0045, //LATIN CAPITAL LETTER E
|
||||
0x0046, //LATIN CAPITAL LETTER F
|
||||
0x0047, //LATIN CAPITAL LETTER G
|
||||
0x0048, //LATIN CAPITAL LETTER H
|
||||
0x0049, //LATIN CAPITAL LETTER I
|
||||
0x004A, //LATIN CAPITAL LETTER J
|
||||
0x004B, //LATIN CAPITAL LETTER K
|
||||
0x004C, //LATIN CAPITAL LETTER L
|
||||
0x004D, //LATIN CAPITAL LETTER M
|
||||
0x004E, //LATIN CAPITAL LETTER N
|
||||
0x004F, //LATIN CAPITAL LETTER O
|
||||
0x0050, //LATIN CAPITAL LETTER P
|
||||
0x0051, //LATIN CAPITAL LETTER Q
|
||||
0x0052, //LATIN CAPITAL LETTER R
|
||||
0x0053, //LATIN CAPITAL LETTER S
|
||||
0x0054, //LATIN CAPITAL LETTER T
|
||||
0x0055, //LATIN CAPITAL LETTER U
|
||||
0x0056, //LATIN CAPITAL LETTER V
|
||||
0x0057, //LATIN CAPITAL LETTER W
|
||||
0x0058, //LATIN CAPITAL LETTER X
|
||||
0x0059, //LATIN CAPITAL LETTER Y
|
||||
0x005A, //LATIN CAPITAL LETTER Z
|
||||
0x005B, //LEFT SQUARE BRACKET
|
||||
0x005C, //REVERSE SOLIDUS
|
||||
0x005D, //RIGHT SQUARE BRACKET
|
||||
0x005E, //CIRCUMFLEX ACCENT
|
||||
0x005F, //LOW LINE
|
||||
0x0060, //GRAVE ACCENT
|
||||
0x0061, //LATIN SMALL LETTER A
|
||||
0x0062, //LATIN SMALL LETTER B
|
||||
0x0063, //LATIN SMALL LETTER C
|
||||
0x0064, //LATIN SMALL LETTER D
|
||||
0x0065, //LATIN SMALL LETTER E
|
||||
0x0066, //LATIN SMALL LETTER F
|
||||
0x0067, //LATIN SMALL LETTER G
|
||||
0x0068, //LATIN SMALL LETTER H
|
||||
0x0069, //LATIN SMALL LETTER I
|
||||
0x006A, //LATIN SMALL LETTER J
|
||||
0x006B, //LATIN SMALL LETTER K
|
||||
0x006C, //LATIN SMALL LETTER L
|
||||
0x006D, //LATIN SMALL LETTER M
|
||||
0x006E, //LATIN SMALL LETTER N
|
||||
0x006F, //LATIN SMALL LETTER O
|
||||
0x0070, //LATIN SMALL LETTER P
|
||||
0x0071, //LATIN SMALL LETTER Q
|
||||
0x0072, //LATIN SMALL LETTER R
|
||||
0x0073, //LATIN SMALL LETTER S
|
||||
0x0074, //LATIN SMALL LETTER T
|
||||
0x0075, //LATIN SMALL LETTER U
|
||||
0x0076, //LATIN SMALL LETTER V
|
||||
0x0077, //LATIN SMALL LETTER W
|
||||
0x0078, //LATIN SMALL LETTER X
|
||||
0x0079, //LATIN SMALL LETTER Y
|
||||
0x007A, //LATIN SMALL LETTER Z
|
||||
0x007B, //LEFT CURLY BRACKET
|
||||
0x007C, //VERTICAL LINE
|
||||
0x007D, //RIGHT CURLY BRACKET
|
||||
0x007E, //TILDE
|
||||
0x007F, //DELETE
|
||||
0x20AC, //EURO SIGN
|
||||
0xFFFD, //UNDEFINED
|
||||
0x201A, //SINGLE LOW-9 QUOTATION MARK
|
||||
0x0192, //LATIN SMALL LETTER F WITH HOOK
|
||||
0x201E, //DOUBLE LOW-9 QUOTATION MARK
|
||||
0x2026, //HORIZONTAL ELLIPSIS
|
||||
0x2020, //DAGGER
|
||||
0x2021, //DOUBLE DAGGER
|
||||
0x02C6, //MODIFIER LETTER CIRCUMFLEX ACCENT
|
||||
0x2030, //PER MILLE SIGN
|
||||
0xFFFD, //UNDEFINED
|
||||
0x2039, //SINGLE LEFT-POINTING ANGLE QUOTATION MARK
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0x2018, //LEFT SINGLE QUOTATION MARK
|
||||
0x2019, //RIGHT SINGLE QUOTATION MARK
|
||||
0x201C, //LEFT DOUBLE QUOTATION MARK
|
||||
0x201D, //RIGHT DOUBLE QUOTATION MARK
|
||||
0x2022, //BULLET
|
||||
0x2013, //EN DASH
|
||||
0x2014, //EM DASH
|
||||
0x02DC, //SMALL TILDE
|
||||
0x2122, //TRADE MARK SIGN
|
||||
0xFFFD, //UNDEFINED
|
||||
0x203A, //SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0x00A0, //NO-BREAK SPACE
|
||||
0x00A1, //INVERTED EXCLAMATION MARK
|
||||
0x00A2, //CENT SIGN
|
||||
0x00A3, //POUND SIGN
|
||||
0x20AA, //NEW SHEQEL SIGN
|
||||
0x00A5, //YEN SIGN
|
||||
0x00A6, //BROKEN BAR
|
||||
0x00A7, //SECTION SIGN
|
||||
0x00A8, //DIAERESIS
|
||||
0x00A9, //COPYRIGHT SIGN
|
||||
0x00D7, //MULTIPLICATION SIGN
|
||||
0x00AB, //LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
|
||||
0x00AC, //NOT SIGN
|
||||
0x00AD, //SOFT HYPHEN
|
||||
0x00AE, //REGISTERED SIGN
|
||||
0x00AF, //MACRON
|
||||
0x00B0, //DEGREE SIGN
|
||||
0x00B1, //PLUS-MINUS SIGN
|
||||
0x00B2, //SUPERSCRIPT TWO
|
||||
0x00B3, //SUPERSCRIPT THREE
|
||||
0x00B4, //ACUTE ACCENT
|
||||
0x00B5, //MICRO SIGN
|
||||
0x00B6, //PILCROW SIGN
|
||||
0x00B7, //MIDDLE DOT
|
||||
0x00B8, //CEDILLA
|
||||
0x00B9, //SUPERSCRIPT ONE
|
||||
0x00F7, //DIVISION SIGN
|
||||
0x00BB, //RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
|
||||
0x00BC, //VULGAR FRACTION ONE QUARTER
|
||||
0x00BD, //VULGAR FRACTION ONE HALF
|
||||
0x00BE, //VULGAR FRACTION THREE QUARTERS
|
||||
0x00BF, //INVERTED QUESTION MARK
|
||||
0x05B0, //HEBREW POINT SHEVA
|
||||
0x05B1, //HEBREW POINT HATAF SEGOL
|
||||
0x05B2, //HEBREW POINT HATAF PATAH
|
||||
0x05B3, //HEBREW POINT HATAF QAMATS
|
||||
0x05B4, //HEBREW POINT HIRIQ
|
||||
0x05B5, //HEBREW POINT TSERE
|
||||
0x05B6, //HEBREW POINT SEGOL
|
||||
0x05B7, //HEBREW POINT PATAH
|
||||
0x05B8, //HEBREW POINT QAMATS
|
||||
0x05B9, //HEBREW POINT HOLAM
|
||||
0xFFFD, //UNDEFINED
|
||||
0x05BB, //HEBREW POINT QUBUTS
|
||||
0x05BC, //HEBREW POINT DAGESH OR MAPIQ
|
||||
0x05BD, //HEBREW POINT METEG
|
||||
0x05BE, //HEBREW PUNCTUATION MAQAF
|
||||
0x05BF, //HEBREW POINT RAFE
|
||||
0x05C0, //HEBREW PUNCTUATION PASEQ
|
||||
0x05C1, //HEBREW POINT SHIN DOT
|
||||
0x05C2, //HEBREW POINT SIN DOT
|
||||
0x05C3, //HEBREW PUNCTUATION SOF PASUQ
|
||||
0x05F0, //HEBREW LIGATURE YIDDISH DOUBLE VAV
|
||||
0x05F1, //HEBREW LIGATURE YIDDISH VAV YOD
|
||||
0x05F2, //HEBREW LIGATURE YIDDISH DOUBLE YOD
|
||||
0x05F3, //HEBREW PUNCTUATION GERESH
|
||||
0x05F4, //HEBREW PUNCTUATION GERSHAYIM
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0x05D0, //HEBREW LETTER ALEF
|
||||
0x05D1, //HEBREW LETTER BET
|
||||
0x05D2, //HEBREW LETTER GIMEL
|
||||
0x05D3, //HEBREW LETTER DALET
|
||||
0x05D4, //HEBREW LETTER HE
|
||||
0x05D5, //HEBREW LETTER VAV
|
||||
0x05D6, //HEBREW LETTER ZAYIN
|
||||
0x05D7, //HEBREW LETTER HET
|
||||
0x05D8, //HEBREW LETTER TET
|
||||
0x05D9, //HEBREW LETTER YOD
|
||||
0x05DA, //HEBREW LETTER FINAL KAF
|
||||
0x05DB, //HEBREW LETTER KAF
|
||||
0x05DC, //HEBREW LETTER LAMED
|
||||
0x05DD, //HEBREW LETTER FINAL MEM
|
||||
0x05DE, //HEBREW LETTER MEM
|
||||
0x05DF, //HEBREW LETTER FINAL NUN
|
||||
0x05E0, //HEBREW LETTER NUN
|
||||
0x05E1, //HEBREW LETTER SAMEKH
|
||||
0x05E2, //HEBREW LETTER AYIN
|
||||
0x05E3, //HEBREW LETTER FINAL PE
|
||||
0x05E4, //HEBREW LETTER PE
|
||||
0x05E5, //HEBREW LETTER FINAL TSADI
|
||||
0x05E6, //HEBREW LETTER TSADI
|
||||
0x05E7, //HEBREW LETTER QOF
|
||||
0x05E8, //HEBREW LETTER RESH
|
||||
0x05E9, //HEBREW LETTER SHIN
|
||||
0x05EA, //HEBREW LETTER TAV
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0x200E, //LEFT-TO-RIGHT MARK
|
||||
0x200F, //RIGHT-TO-LEFT MARK
|
||||
0xFFFD, //UNDEFINED
|
||||
},
|
||||
}
|
|
@ -1,262 +0,0 @@
|
|||
package cp
|
||||
|
||||
var cp1256 *charsetMap = &charsetMap{
|
||||
sb: [256]rune{
|
||||
0x0000, //NULL
|
||||
0x0001, //START OF HEADING
|
||||
0x0002, //START OF TEXT
|
||||
0x0003, //END OF TEXT
|
||||
0x0004, //END OF TRANSMISSION
|
||||
0x0005, //ENQUIRY
|
||||
0x0006, //ACKNOWLEDGE
|
||||
0x0007, //BELL
|
||||
0x0008, //BACKSPACE
|
||||
0x0009, //HORIZONTAL TABULATION
|
||||
0x000A, //LINE FEED
|
||||
0x000B, //VERTICAL TABULATION
|
||||
0x000C, //FORM FEED
|
||||
0x000D, //CARRIAGE RETURN
|
||||
0x000E, //SHIFT OUT
|
||||
0x000F, //SHIFT IN
|
||||
0x0010, //DATA LINK ESCAPE
|
||||
0x0011, //DEVICE CONTROL ONE
|
||||
0x0012, //DEVICE CONTROL TWO
|
||||
0x0013, //DEVICE CONTROL THREE
|
||||
0x0014, //DEVICE CONTROL FOUR
|
||||
0x0015, //NEGATIVE ACKNOWLEDGE
|
||||
0x0016, //SYNCHRONOUS IDLE
|
||||
0x0017, //END OF TRANSMISSION BLOCK
|
||||
0x0018, //CANCEL
|
||||
0x0019, //END OF MEDIUM
|
||||
0x001A, //SUBSTITUTE
|
||||
0x001B, //ESCAPE
|
||||
0x001C, //FILE SEPARATOR
|
||||
0x001D, //GROUP SEPARATOR
|
||||
0x001E, //RECORD SEPARATOR
|
||||
0x001F, //UNIT SEPARATOR
|
||||
0x0020, //SPACE
|
||||
0x0021, //EXCLAMATION MARK
|
||||
0x0022, //QUOTATION MARK
|
||||
0x0023, //NUMBER SIGN
|
||||
0x0024, //DOLLAR SIGN
|
||||
0x0025, //PERCENT SIGN
|
||||
0x0026, //AMPERSAND
|
||||
0x0027, //APOSTROPHE
|
||||
0x0028, //LEFT PARENTHESIS
|
||||
0x0029, //RIGHT PARENTHESIS
|
||||
0x002A, //ASTERISK
|
||||
0x002B, //PLUS SIGN
|
||||
0x002C, //COMMA
|
||||
0x002D, //HYPHEN-MINUS
|
||||
0x002E, //FULL STOP
|
||||
0x002F, //SOLIDUS
|
||||
0x0030, //DIGIT ZERO
|
||||
0x0031, //DIGIT ONE
|
||||
0x0032, //DIGIT TWO
|
||||
0x0033, //DIGIT THREE
|
||||
0x0034, //DIGIT FOUR
|
||||
0x0035, //DIGIT FIVE
|
||||
0x0036, //DIGIT SIX
|
||||
0x0037, //DIGIT SEVEN
|
||||
0x0038, //DIGIT EIGHT
|
||||
0x0039, //DIGIT NINE
|
||||
0x003A, //COLON
|
||||
0x003B, //SEMICOLON
|
||||
0x003C, //LESS-THAN SIGN
|
||||
0x003D, //EQUALS SIGN
|
||||
0x003E, //GREATER-THAN SIGN
|
||||
0x003F, //QUESTION MARK
|
||||
0x0040, //COMMERCIAL AT
|
||||
0x0041, //LATIN CAPITAL LETTER A
|
||||
0x0042, //LATIN CAPITAL LETTER B
|
||||
0x0043, //LATIN CAPITAL LETTER C
|
||||
0x0044, //LATIN CAPITAL LETTER D
|
||||
0x0045, //LATIN CAPITAL LETTER E
|
||||
0x0046, //LATIN CAPITAL LETTER F
|
||||
0x0047, //LATIN CAPITAL LETTER G
|
||||
0x0048, //LATIN CAPITAL LETTER H
|
||||
0x0049, //LATIN CAPITAL LETTER I
|
||||
0x004A, //LATIN CAPITAL LETTER J
|
||||
0x004B, //LATIN CAPITAL LETTER K
|
||||
0x004C, //LATIN CAPITAL LETTER L
|
||||
0x004D, //LATIN CAPITAL LETTER M
|
||||
0x004E, //LATIN CAPITAL LETTER N
|
||||
0x004F, //LATIN CAPITAL LETTER O
|
||||
0x0050, //LATIN CAPITAL LETTER P
|
||||
0x0051, //LATIN CAPITAL LETTER Q
|
||||
0x0052, //LATIN CAPITAL LETTER R
|
||||
0x0053, //LATIN CAPITAL LETTER S
|
||||
0x0054, //LATIN CAPITAL LETTER T
|
||||
0x0055, //LATIN CAPITAL LETTER U
|
||||
0x0056, //LATIN CAPITAL LETTER V
|
||||
0x0057, //LATIN CAPITAL LETTER W
|
||||
0x0058, //LATIN CAPITAL LETTER X
|
||||
0x0059, //LATIN CAPITAL LETTER Y
|
||||
0x005A, //LATIN CAPITAL LETTER Z
|
||||
0x005B, //LEFT SQUARE BRACKET
|
||||
0x005C, //REVERSE SOLIDUS
|
||||
0x005D, //RIGHT SQUARE BRACKET
|
||||
0x005E, //CIRCUMFLEX ACCENT
|
||||
0x005F, //LOW LINE
|
||||
0x0060, //GRAVE ACCENT
|
||||
0x0061, //LATIN SMALL LETTER A
|
||||
0x0062, //LATIN SMALL LETTER B
|
||||
0x0063, //LATIN SMALL LETTER C
|
||||
0x0064, //LATIN SMALL LETTER D
|
||||
0x0065, //LATIN SMALL LETTER E
|
||||
0x0066, //LATIN SMALL LETTER F
|
||||
0x0067, //LATIN SMALL LETTER G
|
||||
0x0068, //LATIN SMALL LETTER H
|
||||
0x0069, //LATIN SMALL LETTER I
|
||||
0x006A, //LATIN SMALL LETTER J
|
||||
0x006B, //LATIN SMALL LETTER K
|
||||
0x006C, //LATIN SMALL LETTER L
|
||||
0x006D, //LATIN SMALL LETTER M
|
||||
0x006E, //LATIN SMALL LETTER N
|
||||
0x006F, //LATIN SMALL LETTER O
|
||||
0x0070, //LATIN SMALL LETTER P
|
||||
0x0071, //LATIN SMALL LETTER Q
|
||||
0x0072, //LATIN SMALL LETTER R
|
||||
0x0073, //LATIN SMALL LETTER S
|
||||
0x0074, //LATIN SMALL LETTER T
|
||||
0x0075, //LATIN SMALL LETTER U
|
||||
0x0076, //LATIN SMALL LETTER V
|
||||
0x0077, //LATIN SMALL LETTER W
|
||||
0x0078, //LATIN SMALL LETTER X
|
||||
0x0079, //LATIN SMALL LETTER Y
|
||||
0x007A, //LATIN SMALL LETTER Z
|
||||
0x007B, //LEFT CURLY BRACKET
|
||||
0x007C, //VERTICAL LINE
|
||||
0x007D, //RIGHT CURLY BRACKET
|
||||
0x007E, //TILDE
|
||||
0x007F, //DELETE
|
||||
0x20AC, //EURO SIGN
|
||||
0x067E, //ARABIC LETTER PEH
|
||||
0x201A, //SINGLE LOW-9 QUOTATION MARK
|
||||
0x0192, //LATIN SMALL LETTER F WITH HOOK
|
||||
0x201E, //DOUBLE LOW-9 QUOTATION MARK
|
||||
0x2026, //HORIZONTAL ELLIPSIS
|
||||
0x2020, //DAGGER
|
||||
0x2021, //DOUBLE DAGGER
|
||||
0x02C6, //MODIFIER LETTER CIRCUMFLEX ACCENT
|
||||
0x2030, //PER MILLE SIGN
|
||||
0x0679, //ARABIC LETTER TTEH
|
||||
0x2039, //SINGLE LEFT-POINTING ANGLE QUOTATION MARK
|
||||
0x0152, //LATIN CAPITAL LIGATURE OE
|
||||
0x0686, //ARABIC LETTER TCHEH
|
||||
0x0698, //ARABIC LETTER JEH
|
||||
0x0688, //ARABIC LETTER DDAL
|
||||
0x06AF, //ARABIC LETTER GAF
|
||||
0x2018, //LEFT SINGLE QUOTATION MARK
|
||||
0x2019, //RIGHT SINGLE QUOTATION MARK
|
||||
0x201C, //LEFT DOUBLE QUOTATION MARK
|
||||
0x201D, //RIGHT DOUBLE QUOTATION MARK
|
||||
0x2022, //BULLET
|
||||
0x2013, //EN DASH
|
||||
0x2014, //EM DASH
|
||||
0x06A9, //ARABIC LETTER KEHEH
|
||||
0x2122, //TRADE MARK SIGN
|
||||
0x0691, //ARABIC LETTER RREH
|
||||
0x203A, //SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
|
||||
0x0153, //LATIN SMALL LIGATURE OE
|
||||
0x200C, //ZERO WIDTH NON-JOINER
|
||||
0x200D, //ZERO WIDTH JOINER
|
||||
0x06BA, //ARABIC LETTER NOON GHUNNA
|
||||
0x00A0, //NO-BREAK SPACE
|
||||
0x060C, //ARABIC COMMA
|
||||
0x00A2, //CENT SIGN
|
||||
0x00A3, //POUND SIGN
|
||||
0x00A4, //CURRENCY SIGN
|
||||
0x00A5, //YEN SIGN
|
||||
0x00A6, //BROKEN BAR
|
||||
0x00A7, //SECTION SIGN
|
||||
0x00A8, //DIAERESIS
|
||||
0x00A9, //COPYRIGHT SIGN
|
||||
0x06BE, //ARABIC LETTER HEH DOACHASHMEE
|
||||
0x00AB, //LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
|
||||
0x00AC, //NOT SIGN
|
||||
0x00AD, //SOFT HYPHEN
|
||||
0x00AE, //REGISTERED SIGN
|
||||
0x00AF, //MACRON
|
||||
0x00B0, //DEGREE SIGN
|
||||
0x00B1, //PLUS-MINUS SIGN
|
||||
0x00B2, //SUPERSCRIPT TWO
|
||||
0x00B3, //SUPERSCRIPT THREE
|
||||
0x00B4, //ACUTE ACCENT
|
||||
0x00B5, //MICRO SIGN
|
||||
0x00B6, //PILCROW SIGN
|
||||
0x00B7, //MIDDLE DOT
|
||||
0x00B8, //CEDILLA
|
||||
0x00B9, //SUPERSCRIPT ONE
|
||||
0x061B, //ARABIC SEMICOLON
|
||||
0x00BB, //RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
|
||||
0x00BC, //VULGAR FRACTION ONE QUARTER
|
||||
0x00BD, //VULGAR FRACTION ONE HALF
|
||||
0x00BE, //VULGAR FRACTION THREE QUARTERS
|
||||
0x061F, //ARABIC QUESTION MARK
|
||||
0x06C1, //ARABIC LETTER HEH GOAL
|
||||
0x0621, //ARABIC LETTER HAMZA
|
||||
0x0622, //ARABIC LETTER ALEF WITH MADDA ABOVE
|
||||
0x0623, //ARABIC LETTER ALEF WITH HAMZA ABOVE
|
||||
0x0624, //ARABIC LETTER WAW WITH HAMZA ABOVE
|
||||
0x0625, //ARABIC LETTER ALEF WITH HAMZA BELOW
|
||||
0x0626, //ARABIC LETTER YEH WITH HAMZA ABOVE
|
||||
0x0627, //ARABIC LETTER ALEF
|
||||
0x0628, //ARABIC LETTER BEH
|
||||
0x0629, //ARABIC LETTER TEH MARBUTA
|
||||
0x062A, //ARABIC LETTER TEH
|
||||
0x062B, //ARABIC LETTER THEH
|
||||
0x062C, //ARABIC LETTER JEEM
|
||||
0x062D, //ARABIC LETTER HAH
|
||||
0x062E, //ARABIC LETTER KHAH
|
||||
0x062F, //ARABIC LETTER DAL
|
||||
0x0630, //ARABIC LETTER THAL
|
||||
0x0631, //ARABIC LETTER REH
|
||||
0x0632, //ARABIC LETTER ZAIN
|
||||
0x0633, //ARABIC LETTER SEEN
|
||||
0x0634, //ARABIC LETTER SHEEN
|
||||
0x0635, //ARABIC LETTER SAD
|
||||
0x0636, //ARABIC LETTER DAD
|
||||
0x00D7, //MULTIPLICATION SIGN
|
||||
0x0637, //ARABIC LETTER TAH
|
||||
0x0638, //ARABIC LETTER ZAH
|
||||
0x0639, //ARABIC LETTER AIN
|
||||
0x063A, //ARABIC LETTER GHAIN
|
||||
0x0640, //ARABIC TATWEEL
|
||||
0x0641, //ARABIC LETTER FEH
|
||||
0x0642, //ARABIC LETTER QAF
|
||||
0x0643, //ARABIC LETTER KAF
|
||||
0x00E0, //LATIN SMALL LETTER A WITH GRAVE
|
||||
0x0644, //ARABIC LETTER LAM
|
||||
0x00E2, //LATIN SMALL LETTER A WITH CIRCUMFLEX
|
||||
0x0645, //ARABIC LETTER MEEM
|
||||
0x0646, //ARABIC LETTER NOON
|
||||
0x0647, //ARABIC LETTER HEH
|
||||
0x0648, //ARABIC LETTER WAW
|
||||
0x00E7, //LATIN SMALL LETTER C WITH CEDILLA
|
||||
0x00E8, //LATIN SMALL LETTER E WITH GRAVE
|
||||
0x00E9, //LATIN SMALL LETTER E WITH ACUTE
|
||||
0x00EA, //LATIN SMALL LETTER E WITH CIRCUMFLEX
|
||||
0x00EB, //LATIN SMALL LETTER E WITH DIAERESIS
|
||||
0x0649, //ARABIC LETTER ALEF MAKSURA
|
||||
0x064A, //ARABIC LETTER YEH
|
||||
0x00EE, //LATIN SMALL LETTER I WITH CIRCUMFLEX
|
||||
0x00EF, //LATIN SMALL LETTER I WITH DIAERESIS
|
||||
0x064B, //ARABIC FATHATAN
|
||||
0x064C, //ARABIC DAMMATAN
|
||||
0x064D, //ARABIC KASRATAN
|
||||
0x064E, //ARABIC FATHA
|
||||
0x00F4, //LATIN SMALL LETTER O WITH CIRCUMFLEX
|
||||
0x064F, //ARABIC DAMMA
|
||||
0x0650, //ARABIC KASRA
|
||||
0x00F7, //DIVISION SIGN
|
||||
0x0651, //ARABIC SHADDA
|
||||
0x00F9, //LATIN SMALL LETTER U WITH GRAVE
|
||||
0x0652, //ARABIC SUKUN
|
||||
0x00FB, //LATIN SMALL LETTER U WITH CIRCUMFLEX
|
||||
0x00FC, //LATIN SMALL LETTER U WITH DIAERESIS
|
||||
0x200E, //LEFT-TO-RIGHT MARK
|
||||
0x200F, //RIGHT-TO-LEFT MARK
|
||||
0x06D2, //ARABIC LETTER YEH BARREE
|
||||
},
|
||||
}
|
|
@ -1,262 +0,0 @@
|
|||
package cp
|
||||
|
||||
var cp1257 *charsetMap = &charsetMap{
|
||||
sb: [256]rune{
|
||||
0x0000, //NULL
|
||||
0x0001, //START OF HEADING
|
||||
0x0002, //START OF TEXT
|
||||
0x0003, //END OF TEXT
|
||||
0x0004, //END OF TRANSMISSION
|
||||
0x0005, //ENQUIRY
|
||||
0x0006, //ACKNOWLEDGE
|
||||
0x0007, //BELL
|
||||
0x0008, //BACKSPACE
|
||||
0x0009, //HORIZONTAL TABULATION
|
||||
0x000A, //LINE FEED
|
||||
0x000B, //VERTICAL TABULATION
|
||||
0x000C, //FORM FEED
|
||||
0x000D, //CARRIAGE RETURN
|
||||
0x000E, //SHIFT OUT
|
||||
0x000F, //SHIFT IN
|
||||
0x0010, //DATA LINK ESCAPE
|
||||
0x0011, //DEVICE CONTROL ONE
|
||||
0x0012, //DEVICE CONTROL TWO
|
||||
0x0013, //DEVICE CONTROL THREE
|
||||
0x0014, //DEVICE CONTROL FOUR
|
||||
0x0015, //NEGATIVE ACKNOWLEDGE
|
||||
0x0016, //SYNCHRONOUS IDLE
|
||||
0x0017, //END OF TRANSMISSION BLOCK
|
||||
0x0018, //CANCEL
|
||||
0x0019, //END OF MEDIUM
|
||||
0x001A, //SUBSTITUTE
|
||||
0x001B, //ESCAPE
|
||||
0x001C, //FILE SEPARATOR
|
||||
0x001D, //GROUP SEPARATOR
|
||||
0x001E, //RECORD SEPARATOR
|
||||
0x001F, //UNIT SEPARATOR
|
||||
0x0020, //SPACE
|
||||
0x0021, //EXCLAMATION MARK
|
||||
0x0022, //QUOTATION MARK
|
||||
0x0023, //NUMBER SIGN
|
||||
0x0024, //DOLLAR SIGN
|
||||
0x0025, //PERCENT SIGN
|
||||
0x0026, //AMPERSAND
|
||||
0x0027, //APOSTROPHE
|
||||
0x0028, //LEFT PARENTHESIS
|
||||
0x0029, //RIGHT PARENTHESIS
|
||||
0x002A, //ASTERISK
|
||||
0x002B, //PLUS SIGN
|
||||
0x002C, //COMMA
|
||||
0x002D, //HYPHEN-MINUS
|
||||
0x002E, //FULL STOP
|
||||
0x002F, //SOLIDUS
|
||||
0x0030, //DIGIT ZERO
|
||||
0x0031, //DIGIT ONE
|
||||
0x0032, //DIGIT TWO
|
||||
0x0033, //DIGIT THREE
|
||||
0x0034, //DIGIT FOUR
|
||||
0x0035, //DIGIT FIVE
|
||||
0x0036, //DIGIT SIX
|
||||
0x0037, //DIGIT SEVEN
|
||||
0x0038, //DIGIT EIGHT
|
||||
0x0039, //DIGIT NINE
|
||||
0x003A, //COLON
|
||||
0x003B, //SEMICOLON
|
||||
0x003C, //LESS-THAN SIGN
|
||||
0x003D, //EQUALS SIGN
|
||||
0x003E, //GREATER-THAN SIGN
|
||||
0x003F, //QUESTION MARK
|
||||
0x0040, //COMMERCIAL AT
|
||||
0x0041, //LATIN CAPITAL LETTER A
|
||||
0x0042, //LATIN CAPITAL LETTER B
|
||||
0x0043, //LATIN CAPITAL LETTER C
|
||||
0x0044, //LATIN CAPITAL LETTER D
|
||||
0x0045, //LATIN CAPITAL LETTER E
|
||||
0x0046, //LATIN CAPITAL LETTER F
|
||||
0x0047, //LATIN CAPITAL LETTER G
|
||||
0x0048, //LATIN CAPITAL LETTER H
|
||||
0x0049, //LATIN CAPITAL LETTER I
|
||||
0x004A, //LATIN CAPITAL LETTER J
|
||||
0x004B, //LATIN CAPITAL LETTER K
|
||||
0x004C, //LATIN CAPITAL LETTER L
|
||||
0x004D, //LATIN CAPITAL LETTER M
|
||||
0x004E, //LATIN CAPITAL LETTER N
|
||||
0x004F, //LATIN CAPITAL LETTER O
|
||||
0x0050, //LATIN CAPITAL LETTER P
|
||||
0x0051, //LATIN CAPITAL LETTER Q
|
||||
0x0052, //LATIN CAPITAL LETTER R
|
||||
0x0053, //LATIN CAPITAL LETTER S
|
||||
0x0054, //LATIN CAPITAL LETTER T
|
||||
0x0055, //LATIN CAPITAL LETTER U
|
||||
0x0056, //LATIN CAPITAL LETTER V
|
||||
0x0057, //LATIN CAPITAL LETTER W
|
||||
0x0058, //LATIN CAPITAL LETTER X
|
||||
0x0059, //LATIN CAPITAL LETTER Y
|
||||
0x005A, //LATIN CAPITAL LETTER Z
|
||||
0x005B, //LEFT SQUARE BRACKET
|
||||
0x005C, //REVERSE SOLIDUS
|
||||
0x005D, //RIGHT SQUARE BRACKET
|
||||
0x005E, //CIRCUMFLEX ACCENT
|
||||
0x005F, //LOW LINE
|
||||
0x0060, //GRAVE ACCENT
|
||||
0x0061, //LATIN SMALL LETTER A
|
||||
0x0062, //LATIN SMALL LETTER B
|
||||
0x0063, //LATIN SMALL LETTER C
|
||||
0x0064, //LATIN SMALL LETTER D
|
||||
0x0065, //LATIN SMALL LETTER E
|
||||
0x0066, //LATIN SMALL LETTER F
|
||||
0x0067, //LATIN SMALL LETTER G
|
||||
0x0068, //LATIN SMALL LETTER H
|
||||
0x0069, //LATIN SMALL LETTER I
|
||||
0x006A, //LATIN SMALL LETTER J
|
||||
0x006B, //LATIN SMALL LETTER K
|
||||
0x006C, //LATIN SMALL LETTER L
|
||||
0x006D, //LATIN SMALL LETTER M
|
||||
0x006E, //LATIN SMALL LETTER N
|
||||
0x006F, //LATIN SMALL LETTER O
|
||||
0x0070, //LATIN SMALL LETTER P
|
||||
0x0071, //LATIN SMALL LETTER Q
|
||||
0x0072, //LATIN SMALL LETTER R
|
||||
0x0073, //LATIN SMALL LETTER S
|
||||
0x0074, //LATIN SMALL LETTER T
|
||||
0x0075, //LATIN SMALL LETTER U
|
||||
0x0076, //LATIN SMALL LETTER V
|
||||
0x0077, //LATIN SMALL LETTER W
|
||||
0x0078, //LATIN SMALL LETTER X
|
||||
0x0079, //LATIN SMALL LETTER Y
|
||||
0x007A, //LATIN SMALL LETTER Z
|
||||
0x007B, //LEFT CURLY BRACKET
|
||||
0x007C, //VERTICAL LINE
|
||||
0x007D, //RIGHT CURLY BRACKET
|
||||
0x007E, //TILDE
|
||||
0x007F, //DELETE
|
||||
0x20AC, //EURO SIGN
|
||||
0xFFFD, //UNDEFINED
|
||||
0x201A, //SINGLE LOW-9 QUOTATION MARK
|
||||
0xFFFD, //UNDEFINED
|
||||
0x201E, //DOUBLE LOW-9 QUOTATION MARK
|
||||
0x2026, //HORIZONTAL ELLIPSIS
|
||||
0x2020, //DAGGER
|
||||
0x2021, //DOUBLE DAGGER
|
||||
0xFFFD, //UNDEFINED
|
||||
0x2030, //PER MILLE SIGN
|
||||
0xFFFD, //UNDEFINED
|
||||
0x2039, //SINGLE LEFT-POINTING ANGLE QUOTATION MARK
|
||||
0xFFFD, //UNDEFINED
|
||||
0x00A8, //DIAERESIS
|
||||
0x02C7, //CARON
|
||||
0x00B8, //CEDILLA
|
||||
0xFFFD, //UNDEFINED
|
||||
0x2018, //LEFT SINGLE QUOTATION MARK
|
||||
0x2019, //RIGHT SINGLE QUOTATION MARK
|
||||
0x201C, //LEFT DOUBLE QUOTATION MARK
|
||||
0x201D, //RIGHT DOUBLE QUOTATION MARK
|
||||
0x2022, //BULLET
|
||||
0x2013, //EN DASH
|
||||
0x2014, //EM DASH
|
||||
0xFFFD, //UNDEFINED
|
||||
0x2122, //TRADE MARK SIGN
|
||||
0xFFFD, //UNDEFINED
|
||||
0x203A, //SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
|
||||
0xFFFD, //UNDEFINED
|
||||
0x00AF, //MACRON
|
||||
0x02DB, //OGONEK
|
||||
0xFFFD, //UNDEFINED
|
||||
0x00A0, //NO-BREAK SPACE
|
||||
0xFFFD, //UNDEFINED
|
||||
0x00A2, //CENT SIGN
|
||||
0x00A3, //POUND SIGN
|
||||
0x00A4, //CURRENCY SIGN
|
||||
0xFFFD, //UNDEFINED
|
||||
0x00A6, //BROKEN BAR
|
||||
0x00A7, //SECTION SIGN
|
||||
0x00D8, //LATIN CAPITAL LETTER O WITH STROKE
|
||||
0x00A9, //COPYRIGHT SIGN
|
||||
0x0156, //LATIN CAPITAL LETTER R WITH CEDILLA
|
||||
0x00AB, //LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
|
||||
0x00AC, //NOT SIGN
|
||||
0x00AD, //SOFT HYPHEN
|
||||
0x00AE, //REGISTERED SIGN
|
||||
0x00C6, //LATIN CAPITAL LETTER AE
|
||||
0x00B0, //DEGREE SIGN
|
||||
0x00B1, //PLUS-MINUS SIGN
|
||||
0x00B2, //SUPERSCRIPT TWO
|
||||
0x00B3, //SUPERSCRIPT THREE
|
||||
0x00B4, //ACUTE ACCENT
|
||||
0x00B5, //MICRO SIGN
|
||||
0x00B6, //PILCROW SIGN
|
||||
0x00B7, //MIDDLE DOT
|
||||
0x00F8, //LATIN SMALL LETTER O WITH STROKE
|
||||
0x00B9, //SUPERSCRIPT ONE
|
||||
0x0157, //LATIN SMALL LETTER R WITH CEDILLA
|
||||
0x00BB, //RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
|
||||
0x00BC, //VULGAR FRACTION ONE QUARTER
|
||||
0x00BD, //VULGAR FRACTION ONE HALF
|
||||
0x00BE, //VULGAR FRACTION THREE QUARTERS
|
||||
0x00E6, //LATIN SMALL LETTER AE
|
||||
0x0104, //LATIN CAPITAL LETTER A WITH OGONEK
|
||||
0x012E, //LATIN CAPITAL LETTER I WITH OGONEK
|
||||
0x0100, //LATIN CAPITAL LETTER A WITH MACRON
|
||||
0x0106, //LATIN CAPITAL LETTER C WITH ACUTE
|
||||
0x00C4, //LATIN CAPITAL LETTER A WITH DIAERESIS
|
||||
0x00C5, //LATIN CAPITAL LETTER A WITH RING ABOVE
|
||||
0x0118, //LATIN CAPITAL LETTER E WITH OGONEK
|
||||
0x0112, //LATIN CAPITAL LETTER E WITH MACRON
|
||||
0x010C, //LATIN CAPITAL LETTER C WITH CARON
|
||||
0x00C9, //LATIN CAPITAL LETTER E WITH ACUTE
|
||||
0x0179, //LATIN CAPITAL LETTER Z WITH ACUTE
|
||||
0x0116, //LATIN CAPITAL LETTER E WITH DOT ABOVE
|
||||
0x0122, //LATIN CAPITAL LETTER G WITH CEDILLA
|
||||
0x0136, //LATIN CAPITAL LETTER K WITH CEDILLA
|
||||
0x012A, //LATIN CAPITAL LETTER I WITH MACRON
|
||||
0x013B, //LATIN CAPITAL LETTER L WITH CEDILLA
|
||||
0x0160, //LATIN CAPITAL LETTER S WITH CARON
|
||||
0x0143, //LATIN CAPITAL LETTER N WITH ACUTE
|
||||
0x0145, //LATIN CAPITAL LETTER N WITH CEDILLA
|
||||
0x00D3, //LATIN CAPITAL LETTER O WITH ACUTE
|
||||
0x014C, //LATIN CAPITAL LETTER O WITH MACRON
|
||||
0x00D5, //LATIN CAPITAL LETTER O WITH TILDE
|
||||
0x00D6, //LATIN CAPITAL LETTER O WITH DIAERESIS
|
||||
0x00D7, //MULTIPLICATION SIGN
|
||||
0x0172, //LATIN CAPITAL LETTER U WITH OGONEK
|
||||
0x0141, //LATIN CAPITAL LETTER L WITH STROKE
|
||||
0x015A, //LATIN CAPITAL LETTER S WITH ACUTE
|
||||
0x016A, //LATIN CAPITAL LETTER U WITH MACRON
|
||||
0x00DC, //LATIN CAPITAL LETTER U WITH DIAERESIS
|
||||
0x017B, //LATIN CAPITAL LETTER Z WITH DOT ABOVE
|
||||
0x017D, //LATIN CAPITAL LETTER Z WITH CARON
|
||||
0x00DF, //LATIN SMALL LETTER SHARP S
|
||||
0x0105, //LATIN SMALL LETTER A WITH OGONEK
|
||||
0x012F, //LATIN SMALL LETTER I WITH OGONEK
|
||||
0x0101, //LATIN SMALL LETTER A WITH MACRON
|
||||
0x0107, //LATIN SMALL LETTER C WITH ACUTE
|
||||
0x00E4, //LATIN SMALL LETTER A WITH DIAERESIS
|
||||
0x00E5, //LATIN SMALL LETTER A WITH RING ABOVE
|
||||
0x0119, //LATIN SMALL LETTER E WITH OGONEK
|
||||
0x0113, //LATIN SMALL LETTER E WITH MACRON
|
||||
0x010D, //LATIN SMALL LETTER C WITH CARON
|
||||
0x00E9, //LATIN SMALL LETTER E WITH ACUTE
|
||||
0x017A, //LATIN SMALL LETTER Z WITH ACUTE
|
||||
0x0117, //LATIN SMALL LETTER E WITH DOT ABOVE
|
||||
0x0123, //LATIN SMALL LETTER G WITH CEDILLA
|
||||
0x0137, //LATIN SMALL LETTER K WITH CEDILLA
|
||||
0x012B, //LATIN SMALL LETTER I WITH MACRON
|
||||
0x013C, //LATIN SMALL LETTER L WITH CEDILLA
|
||||
0x0161, //LATIN SMALL LETTER S WITH CARON
|
||||
0x0144, //LATIN SMALL LETTER N WITH ACUTE
|
||||
0x0146, //LATIN SMALL LETTER N WITH CEDILLA
|
||||
0x00F3, //LATIN SMALL LETTER O WITH ACUTE
|
||||
0x014D, //LATIN SMALL LETTER O WITH MACRON
|
||||
0x00F5, //LATIN SMALL LETTER O WITH TILDE
|
||||
0x00F6, //LATIN SMALL LETTER O WITH DIAERESIS
|
||||
0x00F7, //DIVISION SIGN
|
||||
0x0173, //LATIN SMALL LETTER U WITH OGONEK
|
||||
0x0142, //LATIN SMALL LETTER L WITH STROKE
|
||||
0x015B, //LATIN SMALL LETTER S WITH ACUTE
|
||||
0x016B, //LATIN SMALL LETTER U WITH MACRON
|
||||
0x00FC, //LATIN SMALL LETTER U WITH DIAERESIS
|
||||
0x017C, //LATIN SMALL LETTER Z WITH DOT ABOVE
|
||||
0x017E, //LATIN SMALL LETTER Z WITH CARON
|
||||
0x02D9, //DOT ABOVE
|
||||
},
|
||||
}
|
|
@ -1,262 +0,0 @@
|
|||
package cp
|
||||
|
||||
var cp1258 *charsetMap = &charsetMap{
|
||||
sb: [256]rune{
|
||||
0x0000, //NULL
|
||||
0x0001, //START OF HEADING
|
||||
0x0002, //START OF TEXT
|
||||
0x0003, //END OF TEXT
|
||||
0x0004, //END OF TRANSMISSION
|
||||
0x0005, //ENQUIRY
|
||||
0x0006, //ACKNOWLEDGE
|
||||
0x0007, //BELL
|
||||
0x0008, //BACKSPACE
|
||||
0x0009, //HORIZONTAL TABULATION
|
||||
0x000A, //LINE FEED
|
||||
0x000B, //VERTICAL TABULATION
|
||||
0x000C, //FORM FEED
|
||||
0x000D, //CARRIAGE RETURN
|
||||
0x000E, //SHIFT OUT
|
||||
0x000F, //SHIFT IN
|
||||
0x0010, //DATA LINK ESCAPE
|
||||
0x0011, //DEVICE CONTROL ONE
|
||||
0x0012, //DEVICE CONTROL TWO
|
||||
0x0013, //DEVICE CONTROL THREE
|
||||
0x0014, //DEVICE CONTROL FOUR
|
||||
0x0015, //NEGATIVE ACKNOWLEDGE
|
||||
0x0016, //SYNCHRONOUS IDLE
|
||||
0x0017, //END OF TRANSMISSION BLOCK
|
||||
0x0018, //CANCEL
|
||||
0x0019, //END OF MEDIUM
|
||||
0x001A, //SUBSTITUTE
|
||||
0x001B, //ESCAPE
|
||||
0x001C, //FILE SEPARATOR
|
||||
0x001D, //GROUP SEPARATOR
|
||||
0x001E, //RECORD SEPARATOR
|
||||
0x001F, //UNIT SEPARATOR
|
||||
0x0020, //SPACE
|
||||
0x0021, //EXCLAMATION MARK
|
||||
0x0022, //QUOTATION MARK
|
||||
0x0023, //NUMBER SIGN
|
||||
0x0024, //DOLLAR SIGN
|
||||
0x0025, //PERCENT SIGN
|
||||
0x0026, //AMPERSAND
|
||||
0x0027, //APOSTROPHE
|
||||
0x0028, //LEFT PARENTHESIS
|
||||
0x0029, //RIGHT PARENTHESIS
|
||||
0x002A, //ASTERISK
|
||||
0x002B, //PLUS SIGN
|
||||
0x002C, //COMMA
|
||||
0x002D, //HYPHEN-MINUS
|
||||
0x002E, //FULL STOP
|
||||
0x002F, //SOLIDUS
|
||||
0x0030, //DIGIT ZERO
|
||||
0x0031, //DIGIT ONE
|
||||
0x0032, //DIGIT TWO
|
||||
0x0033, //DIGIT THREE
|
||||
0x0034, //DIGIT FOUR
|
||||
0x0035, //DIGIT FIVE
|
||||
0x0036, //DIGIT SIX
|
||||
0x0037, //DIGIT SEVEN
|
||||
0x0038, //DIGIT EIGHT
|
||||
0x0039, //DIGIT NINE
|
||||
0x003A, //COLON
|
||||
0x003B, //SEMICOLON
|
||||
0x003C, //LESS-THAN SIGN
|
||||
0x003D, //EQUALS SIGN
|
||||
0x003E, //GREATER-THAN SIGN
|
||||
0x003F, //QUESTION MARK
|
||||
0x0040, //COMMERCIAL AT
|
||||
0x0041, //LATIN CAPITAL LETTER A
|
||||
0x0042, //LATIN CAPITAL LETTER B
|
||||
0x0043, //LATIN CAPITAL LETTER C
|
||||
0x0044, //LATIN CAPITAL LETTER D
|
||||
0x0045, //LATIN CAPITAL LETTER E
|
||||
0x0046, //LATIN CAPITAL LETTER F
|
||||
0x0047, //LATIN CAPITAL LETTER G
|
||||
0x0048, //LATIN CAPITAL LETTER H
|
||||
0x0049, //LATIN CAPITAL LETTER I
|
||||
0x004A, //LATIN CAPITAL LETTER J
|
||||
0x004B, //LATIN CAPITAL LETTER K
|
||||
0x004C, //LATIN CAPITAL LETTER L
|
||||
0x004D, //LATIN CAPITAL LETTER M
|
||||
0x004E, //LATIN CAPITAL LETTER N
|
||||
0x004F, //LATIN CAPITAL LETTER O
|
||||
0x0050, //LATIN CAPITAL LETTER P
|
||||
0x0051, //LATIN CAPITAL LETTER Q
|
||||
0x0052, //LATIN CAPITAL LETTER R
|
||||
0x0053, //LATIN CAPITAL LETTER S
|
||||
0x0054, //LATIN CAPITAL LETTER T
|
||||
0x0055, //LATIN CAPITAL LETTER U
|
||||
0x0056, //LATIN CAPITAL LETTER V
|
||||
0x0057, //LATIN CAPITAL LETTER W
|
||||
0x0058, //LATIN CAPITAL LETTER X
|
||||
0x0059, //LATIN CAPITAL LETTER Y
|
||||
0x005A, //LATIN CAPITAL LETTER Z
|
||||
0x005B, //LEFT SQUARE BRACKET
|
||||
0x005C, //REVERSE SOLIDUS
|
||||
0x005D, //RIGHT SQUARE BRACKET
|
||||
0x005E, //CIRCUMFLEX ACCENT
|
||||
0x005F, //LOW LINE
|
||||
0x0060, //GRAVE ACCENT
|
||||
0x0061, //LATIN SMALL LETTER A
|
||||
0x0062, //LATIN SMALL LETTER B
|
||||
0x0063, //LATIN SMALL LETTER C
|
||||
0x0064, //LATIN SMALL LETTER D
|
||||
0x0065, //LATIN SMALL LETTER E
|
||||
0x0066, //LATIN SMALL LETTER F
|
||||
0x0067, //LATIN SMALL LETTER G
|
||||
0x0068, //LATIN SMALL LETTER H
|
||||
0x0069, //LATIN SMALL LETTER I
|
||||
0x006A, //LATIN SMALL LETTER J
|
||||
0x006B, //LATIN SMALL LETTER K
|
||||
0x006C, //LATIN SMALL LETTER L
|
||||
0x006D, //LATIN SMALL LETTER M
|
||||
0x006E, //LATIN SMALL LETTER N
|
||||
0x006F, //LATIN SMALL LETTER O
|
||||
0x0070, //LATIN SMALL LETTER P
|
||||
0x0071, //LATIN SMALL LETTER Q
|
||||
0x0072, //LATIN SMALL LETTER R
|
||||
0x0073, //LATIN SMALL LETTER S
|
||||
0x0074, //LATIN SMALL LETTER T
|
||||
0x0075, //LATIN SMALL LETTER U
|
||||
0x0076, //LATIN SMALL LETTER V
|
||||
0x0077, //LATIN SMALL LETTER W
|
||||
0x0078, //LATIN SMALL LETTER X
|
||||
0x0079, //LATIN SMALL LETTER Y
|
||||
0x007A, //LATIN SMALL LETTER Z
|
||||
0x007B, //LEFT CURLY BRACKET
|
||||
0x007C, //VERTICAL LINE
|
||||
0x007D, //RIGHT CURLY BRACKET
|
||||
0x007E, //TILDE
|
||||
0x007F, //DELETE
|
||||
0x20AC, //EURO SIGN
|
||||
0xFFFD, //UNDEFINED
|
||||
0x201A, //SINGLE LOW-9 QUOTATION MARK
|
||||
0x0192, //LATIN SMALL LETTER F WITH HOOK
|
||||
0x201E, //DOUBLE LOW-9 QUOTATION MARK
|
||||
0x2026, //HORIZONTAL ELLIPSIS
|
||||
0x2020, //DAGGER
|
||||
0x2021, //DOUBLE DAGGER
|
||||
0x02C6, //MODIFIER LETTER CIRCUMFLEX ACCENT
|
||||
0x2030, //PER MILLE SIGN
|
||||
0xFFFD, //UNDEFINED
|
||||
0x2039, //SINGLE LEFT-POINTING ANGLE QUOTATION MARK
|
||||
0x0152, //LATIN CAPITAL LIGATURE OE
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0x2018, //LEFT SINGLE QUOTATION MARK
|
||||
0x2019, //RIGHT SINGLE QUOTATION MARK
|
||||
0x201C, //LEFT DOUBLE QUOTATION MARK
|
||||
0x201D, //RIGHT DOUBLE QUOTATION MARK
|
||||
0x2022, //BULLET
|
||||
0x2013, //EN DASH
|
||||
0x2014, //EM DASH
|
||||
0x02DC, //SMALL TILDE
|
||||
0x2122, //TRADE MARK SIGN
|
||||
0xFFFD, //UNDEFINED
|
||||
0x203A, //SINGLE RIGHT-POINTING ANGLE QUOTATION MARK
|
||||
0x0153, //LATIN SMALL LIGATURE OE
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0x0178, //LATIN CAPITAL LETTER Y WITH DIAERESIS
|
||||
0x00A0, //NO-BREAK SPACE
|
||||
0x00A1, //INVERTED EXCLAMATION MARK
|
||||
0x00A2, //CENT SIGN
|
||||
0x00A3, //POUND SIGN
|
||||
0x00A4, //CURRENCY SIGN
|
||||
0x00A5, //YEN SIGN
|
||||
0x00A6, //BROKEN BAR
|
||||
0x00A7, //SECTION SIGN
|
||||
0x00A8, //DIAERESIS
|
||||
0x00A9, //COPYRIGHT SIGN
|
||||
0x00AA, //FEMININE ORDINAL INDICATOR
|
||||
0x00AB, //LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
|
||||
0x00AC, //NOT SIGN
|
||||
0x00AD, //SOFT HYPHEN
|
||||
0x00AE, //REGISTERED SIGN
|
||||
0x00AF, //MACRON
|
||||
0x00B0, //DEGREE SIGN
|
||||
0x00B1, //PLUS-MINUS SIGN
|
||||
0x00B2, //SUPERSCRIPT TWO
|
||||
0x00B3, //SUPERSCRIPT THREE
|
||||
0x00B4, //ACUTE ACCENT
|
||||
0x00B5, //MICRO SIGN
|
||||
0x00B6, //PILCROW SIGN
|
||||
0x00B7, //MIDDLE DOT
|
||||
0x00B8, //CEDILLA
|
||||
0x00B9, //SUPERSCRIPT ONE
|
||||
0x00BA, //MASCULINE ORDINAL INDICATOR
|
||||
0x00BB, //RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
|
||||
0x00BC, //VULGAR FRACTION ONE QUARTER
|
||||
0x00BD, //VULGAR FRACTION ONE HALF
|
||||
0x00BE, //VULGAR FRACTION THREE QUARTERS
|
||||
0x00BF, //INVERTED QUESTION MARK
|
||||
0x00C0, //LATIN CAPITAL LETTER A WITH GRAVE
|
||||
0x00C1, //LATIN CAPITAL LETTER A WITH ACUTE
|
||||
0x00C2, //LATIN CAPITAL LETTER A WITH CIRCUMFLEX
|
||||
0x0102, //LATIN CAPITAL LETTER A WITH BREVE
|
||||
0x00C4, //LATIN CAPITAL LETTER A WITH DIAERESIS
|
||||
0x00C5, //LATIN CAPITAL LETTER A WITH RING ABOVE
|
||||
0x00C6, //LATIN CAPITAL LETTER AE
|
||||
0x00C7, //LATIN CAPITAL LETTER C WITH CEDILLA
|
||||
0x00C8, //LATIN CAPITAL LETTER E WITH GRAVE
|
||||
0x00C9, //LATIN CAPITAL LETTER E WITH ACUTE
|
||||
0x00CA, //LATIN CAPITAL LETTER E WITH CIRCUMFLEX
|
||||
0x00CB, //LATIN CAPITAL LETTER E WITH DIAERESIS
|
||||
0x0300, //COMBINING GRAVE ACCENT
|
||||
0x00CD, //LATIN CAPITAL LETTER I WITH ACUTE
|
||||
0x00CE, //LATIN CAPITAL LETTER I WITH CIRCUMFLEX
|
||||
0x00CF, //LATIN CAPITAL LETTER I WITH DIAERESIS
|
||||
0x0110, //LATIN CAPITAL LETTER D WITH STROKE
|
||||
0x00D1, //LATIN CAPITAL LETTER N WITH TILDE
|
||||
0x0309, //COMBINING HOOK ABOVE
|
||||
0x00D3, //LATIN CAPITAL LETTER O WITH ACUTE
|
||||
0x00D4, //LATIN CAPITAL LETTER O WITH CIRCUMFLEX
|
||||
0x01A0, //LATIN CAPITAL LETTER O WITH HORN
|
||||
0x00D6, //LATIN CAPITAL LETTER O WITH DIAERESIS
|
||||
0x00D7, //MULTIPLICATION SIGN
|
||||
0x00D8, //LATIN CAPITAL LETTER O WITH STROKE
|
||||
0x00D9, //LATIN CAPITAL LETTER U WITH GRAVE
|
||||
0x00DA, //LATIN CAPITAL LETTER U WITH ACUTE
|
||||
0x00DB, //LATIN CAPITAL LETTER U WITH CIRCUMFLEX
|
||||
0x00DC, //LATIN CAPITAL LETTER U WITH DIAERESIS
|
||||
0x01AF, //LATIN CAPITAL LETTER U WITH HORN
|
||||
0x0303, //COMBINING TILDE
|
||||
0x00DF, //LATIN SMALL LETTER SHARP S
|
||||
0x00E0, //LATIN SMALL LETTER A WITH GRAVE
|
||||
0x00E1, //LATIN SMALL LETTER A WITH ACUTE
|
||||
0x00E2, //LATIN SMALL LETTER A WITH CIRCUMFLEX
|
||||
0x0103, //LATIN SMALL LETTER A WITH BREVE
|
||||
0x00E4, //LATIN SMALL LETTER A WITH DIAERESIS
|
||||
0x00E5, //LATIN SMALL LETTER A WITH RING ABOVE
|
||||
0x00E6, //LATIN SMALL LETTER AE
|
||||
0x00E7, //LATIN SMALL LETTER C WITH CEDILLA
|
||||
0x00E8, //LATIN SMALL LETTER E WITH GRAVE
|
||||
0x00E9, //LATIN SMALL LETTER E WITH ACUTE
|
||||
0x00EA, //LATIN SMALL LETTER E WITH CIRCUMFLEX
|
||||
0x00EB, //LATIN SMALL LETTER E WITH DIAERESIS
|
||||
0x0301, //COMBINING ACUTE ACCENT
|
||||
0x00ED, //LATIN SMALL LETTER I WITH ACUTE
|
||||
0x00EE, //LATIN SMALL LETTER I WITH CIRCUMFLEX
|
||||
0x00EF, //LATIN SMALL LETTER I WITH DIAERESIS
|
||||
0x0111, //LATIN SMALL LETTER D WITH STROKE
|
||||
0x00F1, //LATIN SMALL LETTER N WITH TILDE
|
||||
0x0323, //COMBINING DOT BELOW
|
||||
0x00F3, //LATIN SMALL LETTER O WITH ACUTE
|
||||
0x00F4, //LATIN SMALL LETTER O WITH CIRCUMFLEX
|
||||
0x01A1, //LATIN SMALL LETTER O WITH HORN
|
||||
0x00F6, //LATIN SMALL LETTER O WITH DIAERESIS
|
||||
0x00F7, //DIVISION SIGN
|
||||
0x00F8, //LATIN SMALL LETTER O WITH STROKE
|
||||
0x00F9, //LATIN SMALL LETTER U WITH GRAVE
|
||||
0x00FA, //LATIN SMALL LETTER U WITH ACUTE
|
||||
0x00FB, //LATIN SMALL LETTER U WITH CIRCUMFLEX
|
||||
0x00FC, //LATIN SMALL LETTER U WITH DIAERESIS
|
||||
0x01B0, //LATIN SMALL LETTER U WITH HORN
|
||||
0x20AB, //DONG SIGN
|
||||
0x00FF, //LATIN SMALL LETTER Y WITH DIAERESIS
|
||||
},
|
||||
}
|
|
@ -1,262 +0,0 @@
|
|||
package cp
|
||||
|
||||
var cp437 *charsetMap = &charsetMap{
|
||||
sb: [256]rune{
|
||||
0x0000, //NULL
|
||||
0x0001, //START OF HEADING
|
||||
0x0002, //START OF TEXT
|
||||
0x0003, //END OF TEXT
|
||||
0x0004, //END OF TRANSMISSION
|
||||
0x0005, //ENQUIRY
|
||||
0x0006, //ACKNOWLEDGE
|
||||
0x0007, //BELL
|
||||
0x0008, //BACKSPACE
|
||||
0x0009, //HORIZONTAL TABULATION
|
||||
0x000a, //LINE FEED
|
||||
0x000b, //VERTICAL TABULATION
|
||||
0x000c, //FORM FEED
|
||||
0x000d, //CARRIAGE RETURN
|
||||
0x000e, //SHIFT OUT
|
||||
0x000f, //SHIFT IN
|
||||
0x0010, //DATA LINK ESCAPE
|
||||
0x0011, //DEVICE CONTROL ONE
|
||||
0x0012, //DEVICE CONTROL TWO
|
||||
0x0013, //DEVICE CONTROL THREE
|
||||
0x0014, //DEVICE CONTROL FOUR
|
||||
0x0015, //NEGATIVE ACKNOWLEDGE
|
||||
0x0016, //SYNCHRONOUS IDLE
|
||||
0x0017, //END OF TRANSMISSION BLOCK
|
||||
0x0018, //CANCEL
|
||||
0x0019, //END OF MEDIUM
|
||||
0x001a, //SUBSTITUTE
|
||||
0x001b, //ESCAPE
|
||||
0x001c, //FILE SEPARATOR
|
||||
0x001d, //GROUP SEPARATOR
|
||||
0x001e, //RECORD SEPARATOR
|
||||
0x001f, //UNIT SEPARATOR
|
||||
0x0020, //SPACE
|
||||
0x0021, //EXCLAMATION MARK
|
||||
0x0022, //QUOTATION MARK
|
||||
0x0023, //NUMBER SIGN
|
||||
0x0024, //DOLLAR SIGN
|
||||
0x0025, //PERCENT SIGN
|
||||
0x0026, //AMPERSAND
|
||||
0x0027, //APOSTROPHE
|
||||
0x0028, //LEFT PARENTHESIS
|
||||
0x0029, //RIGHT PARENTHESIS
|
||||
0x002a, //ASTERISK
|
||||
0x002b, //PLUS SIGN
|
||||
0x002c, //COMMA
|
||||
0x002d, //HYPHEN-MINUS
|
||||
0x002e, //FULL STOP
|
||||
0x002f, //SOLIDUS
|
||||
0x0030, //DIGIT ZERO
|
||||
0x0031, //DIGIT ONE
|
||||
0x0032, //DIGIT TWO
|
||||
0x0033, //DIGIT THREE
|
||||
0x0034, //DIGIT FOUR
|
||||
0x0035, //DIGIT FIVE
|
||||
0x0036, //DIGIT SIX
|
||||
0x0037, //DIGIT SEVEN
|
||||
0x0038, //DIGIT EIGHT
|
||||
0x0039, //DIGIT NINE
|
||||
0x003a, //COLON
|
||||
0x003b, //SEMICOLON
|
||||
0x003c, //LESS-THAN SIGN
|
||||
0x003d, //EQUALS SIGN
|
||||
0x003e, //GREATER-THAN SIGN
|
||||
0x003f, //QUESTION MARK
|
||||
0x0040, //COMMERCIAL AT
|
||||
0x0041, //LATIN CAPITAL LETTER A
|
||||
0x0042, //LATIN CAPITAL LETTER B
|
||||
0x0043, //LATIN CAPITAL LETTER C
|
||||
0x0044, //LATIN CAPITAL LETTER D
|
||||
0x0045, //LATIN CAPITAL LETTER E
|
||||
0x0046, //LATIN CAPITAL LETTER F
|
||||
0x0047, //LATIN CAPITAL LETTER G
|
||||
0x0048, //LATIN CAPITAL LETTER H
|
||||
0x0049, //LATIN CAPITAL LETTER I
|
||||
0x004a, //LATIN CAPITAL LETTER J
|
||||
0x004b, //LATIN CAPITAL LETTER K
|
||||
0x004c, //LATIN CAPITAL LETTER L
|
||||
0x004d, //LATIN CAPITAL LETTER M
|
||||
0x004e, //LATIN CAPITAL LETTER N
|
||||
0x004f, //LATIN CAPITAL LETTER O
|
||||
0x0050, //LATIN CAPITAL LETTER P
|
||||
0x0051, //LATIN CAPITAL LETTER Q
|
||||
0x0052, //LATIN CAPITAL LETTER R
|
||||
0x0053, //LATIN CAPITAL LETTER S
|
||||
0x0054, //LATIN CAPITAL LETTER T
|
||||
0x0055, //LATIN CAPITAL LETTER U
|
||||
0x0056, //LATIN CAPITAL LETTER V
|
||||
0x0057, //LATIN CAPITAL LETTER W
|
||||
0x0058, //LATIN CAPITAL LETTER X
|
||||
0x0059, //LATIN CAPITAL LETTER Y
|
||||
0x005a, //LATIN CAPITAL LETTER Z
|
||||
0x005b, //LEFT SQUARE BRACKET
|
||||
0x005c, //REVERSE SOLIDUS
|
||||
0x005d, //RIGHT SQUARE BRACKET
|
||||
0x005e, //CIRCUMFLEX ACCENT
|
||||
0x005f, //LOW LINE
|
||||
0x0060, //GRAVE ACCENT
|
||||
0x0061, //LATIN SMALL LETTER A
|
||||
0x0062, //LATIN SMALL LETTER B
|
||||
0x0063, //LATIN SMALL LETTER C
|
||||
0x0064, //LATIN SMALL LETTER D
|
||||
0x0065, //LATIN SMALL LETTER E
|
||||
0x0066, //LATIN SMALL LETTER F
|
||||
0x0067, //LATIN SMALL LETTER G
|
||||
0x0068, //LATIN SMALL LETTER H
|
||||
0x0069, //LATIN SMALL LETTER I
|
||||
0x006a, //LATIN SMALL LETTER J
|
||||
0x006b, //LATIN SMALL LETTER K
|
||||
0x006c, //LATIN SMALL LETTER L
|
||||
0x006d, //LATIN SMALL LETTER M
|
||||
0x006e, //LATIN SMALL LETTER N
|
||||
0x006f, //LATIN SMALL LETTER O
|
||||
0x0070, //LATIN SMALL LETTER P
|
||||
0x0071, //LATIN SMALL LETTER Q
|
||||
0x0072, //LATIN SMALL LETTER R
|
||||
0x0073, //LATIN SMALL LETTER S
|
||||
0x0074, //LATIN SMALL LETTER T
|
||||
0x0075, //LATIN SMALL LETTER U
|
||||
0x0076, //LATIN SMALL LETTER V
|
||||
0x0077, //LATIN SMALL LETTER W
|
||||
0x0078, //LATIN SMALL LETTER X
|
||||
0x0079, //LATIN SMALL LETTER Y
|
||||
0x007a, //LATIN SMALL LETTER Z
|
||||
0x007b, //LEFT CURLY BRACKET
|
||||
0x007c, //VERTICAL LINE
|
||||
0x007d, //RIGHT CURLY BRACKET
|
||||
0x007e, //TILDE
|
||||
0x007f, //DELETE
|
||||
0x00c7, //LATIN CAPITAL LETTER C WITH CEDILLA
|
||||
0x00fc, //LATIN SMALL LETTER U WITH DIAERESIS
|
||||
0x00e9, //LATIN SMALL LETTER E WITH ACUTE
|
||||
0x00e2, //LATIN SMALL LETTER A WITH CIRCUMFLEX
|
||||
0x00e4, //LATIN SMALL LETTER A WITH DIAERESIS
|
||||
0x00e0, //LATIN SMALL LETTER A WITH GRAVE
|
||||
0x00e5, //LATIN SMALL LETTER A WITH RING ABOVE
|
||||
0x00e7, //LATIN SMALL LETTER C WITH CEDILLA
|
||||
0x00ea, //LATIN SMALL LETTER E WITH CIRCUMFLEX
|
||||
0x00eb, //LATIN SMALL LETTER E WITH DIAERESIS
|
||||
0x00e8, //LATIN SMALL LETTER E WITH GRAVE
|
||||
0x00ef, //LATIN SMALL LETTER I WITH DIAERESIS
|
||||
0x00ee, //LATIN SMALL LETTER I WITH CIRCUMFLEX
|
||||
0x00ec, //LATIN SMALL LETTER I WITH GRAVE
|
||||
0x00c4, //LATIN CAPITAL LETTER A WITH DIAERESIS
|
||||
0x00c5, //LATIN CAPITAL LETTER A WITH RING ABOVE
|
||||
0x00c9, //LATIN CAPITAL LETTER E WITH ACUTE
|
||||
0x00e6, //LATIN SMALL LIGATURE AE
|
||||
0x00c6, //LATIN CAPITAL LIGATURE AE
|
||||
0x00f4, //LATIN SMALL LETTER O WITH CIRCUMFLEX
|
||||
0x00f6, //LATIN SMALL LETTER O WITH DIAERESIS
|
||||
0x00f2, //LATIN SMALL LETTER O WITH GRAVE
|
||||
0x00fb, //LATIN SMALL LETTER U WITH CIRCUMFLEX
|
||||
0x00f9, //LATIN SMALL LETTER U WITH GRAVE
|
||||
0x00ff, //LATIN SMALL LETTER Y WITH DIAERESIS
|
||||
0x00d6, //LATIN CAPITAL LETTER O WITH DIAERESIS
|
||||
0x00dc, //LATIN CAPITAL LETTER U WITH DIAERESIS
|
||||
0x00a2, //CENT SIGN
|
||||
0x00a3, //POUND SIGN
|
||||
0x00a5, //YEN SIGN
|
||||
0x20a7, //PESETA SIGN
|
||||
0x0192, //LATIN SMALL LETTER F WITH HOOK
|
||||
0x00e1, //LATIN SMALL LETTER A WITH ACUTE
|
||||
0x00ed, //LATIN SMALL LETTER I WITH ACUTE
|
||||
0x00f3, //LATIN SMALL LETTER O WITH ACUTE
|
||||
0x00fa, //LATIN SMALL LETTER U WITH ACUTE
|
||||
0x00f1, //LATIN SMALL LETTER N WITH TILDE
|
||||
0x00d1, //LATIN CAPITAL LETTER N WITH TILDE
|
||||
0x00aa, //FEMININE ORDINAL INDICATOR
|
||||
0x00ba, //MASCULINE ORDINAL INDICATOR
|
||||
0x00bf, //INVERTED QUESTION MARK
|
||||
0x2310, //REVERSED NOT SIGN
|
||||
0x00ac, //NOT SIGN
|
||||
0x00bd, //VULGAR FRACTION ONE HALF
|
||||
0x00bc, //VULGAR FRACTION ONE QUARTER
|
||||
0x00a1, //INVERTED EXCLAMATION MARK
|
||||
0x00ab, //LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
|
||||
0x00bb, //RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
|
||||
0x2591, //LIGHT SHADE
|
||||
0x2592, //MEDIUM SHADE
|
||||
0x2593, //DARK SHADE
|
||||
0x2502, //BOX DRAWINGS LIGHT VERTICAL
|
||||
0x2524, //BOX DRAWINGS LIGHT VERTICAL AND LEFT
|
||||
0x2561, //BOX DRAWINGS VERTICAL SINGLE AND LEFT DOUBLE
|
||||
0x2562, //BOX DRAWINGS VERTICAL DOUBLE AND LEFT SINGLE
|
||||
0x2556, //BOX DRAWINGS DOWN DOUBLE AND LEFT SINGLE
|
||||
0x2555, //BOX DRAWINGS DOWN SINGLE AND LEFT DOUBLE
|
||||
0x2563, //BOX DRAWINGS DOUBLE VERTICAL AND LEFT
|
||||
0x2551, //BOX DRAWINGS DOUBLE VERTICAL
|
||||
0x2557, //BOX DRAWINGS DOUBLE DOWN AND LEFT
|
||||
0x255d, //BOX DRAWINGS DOUBLE UP AND LEFT
|
||||
0x255c, //BOX DRAWINGS UP DOUBLE AND LEFT SINGLE
|
||||
0x255b, //BOX DRAWINGS UP SINGLE AND LEFT DOUBLE
|
||||
0x2510, //BOX DRAWINGS LIGHT DOWN AND LEFT
|
||||
0x2514, //BOX DRAWINGS LIGHT UP AND RIGHT
|
||||
0x2534, //BOX DRAWINGS LIGHT UP AND HORIZONTAL
|
||||
0x252c, //BOX DRAWINGS LIGHT DOWN AND HORIZONTAL
|
||||
0x251c, //BOX DRAWINGS LIGHT VERTICAL AND RIGHT
|
||||
0x2500, //BOX DRAWINGS LIGHT HORIZONTAL
|
||||
0x253c, //BOX DRAWINGS LIGHT VERTICAL AND HORIZONTAL
|
||||
0x255e, //BOX DRAWINGS VERTICAL SINGLE AND RIGHT DOUBLE
|
||||
0x255f, //BOX DRAWINGS VERTICAL DOUBLE AND RIGHT SINGLE
|
||||
0x255a, //BOX DRAWINGS DOUBLE UP AND RIGHT
|
||||
0x2554, //BOX DRAWINGS DOUBLE DOWN AND RIGHT
|
||||
0x2569, //BOX DRAWINGS DOUBLE UP AND HORIZONTAL
|
||||
0x2566, //BOX DRAWINGS DOUBLE DOWN AND HORIZONTAL
|
||||
0x2560, //BOX DRAWINGS DOUBLE VERTICAL AND RIGHT
|
||||
0x2550, //BOX DRAWINGS DOUBLE HORIZONTAL
|
||||
0x256c, //BOX DRAWINGS DOUBLE VERTICAL AND HORIZONTAL
|
||||
0x2567, //BOX DRAWINGS UP SINGLE AND HORIZONTAL DOUBLE
|
||||
0x2568, //BOX DRAWINGS UP DOUBLE AND HORIZONTAL SINGLE
|
||||
0x2564, //BOX DRAWINGS DOWN SINGLE AND HORIZONTAL DOUBLE
|
||||
0x2565, //BOX DRAWINGS DOWN DOUBLE AND HORIZONTAL SINGLE
|
||||
0x2559, //BOX DRAWINGS UP DOUBLE AND RIGHT SINGLE
|
||||
0x2558, //BOX DRAWINGS UP SINGLE AND RIGHT DOUBLE
|
||||
0x2552, //BOX DRAWINGS DOWN SINGLE AND RIGHT DOUBLE
|
||||
0x2553, //BOX DRAWINGS DOWN DOUBLE AND RIGHT SINGLE
|
||||
0x256b, //BOX DRAWINGS VERTICAL DOUBLE AND HORIZONTAL SINGLE
|
||||
0x256a, //BOX DRAWINGS VERTICAL SINGLE AND HORIZONTAL DOUBLE
|
||||
0x2518, //BOX DRAWINGS LIGHT UP AND LEFT
|
||||
0x250c, //BOX DRAWINGS LIGHT DOWN AND RIGHT
|
||||
0x2588, //FULL BLOCK
|
||||
0x2584, //LOWER HALF BLOCK
|
||||
0x258c, //LEFT HALF BLOCK
|
||||
0x2590, //RIGHT HALF BLOCK
|
||||
0x2580, //UPPER HALF BLOCK
|
||||
0x03b1, //GREEK SMALL LETTER ALPHA
|
||||
0x00df, //LATIN SMALL LETTER SHARP S
|
||||
0x0393, //GREEK CAPITAL LETTER GAMMA
|
||||
0x03c0, //GREEK SMALL LETTER PI
|
||||
0x03a3, //GREEK CAPITAL LETTER SIGMA
|
||||
0x03c3, //GREEK SMALL LETTER SIGMA
|
||||
0x00b5, //MICRO SIGN
|
||||
0x03c4, //GREEK SMALL LETTER TAU
|
||||
0x03a6, //GREEK CAPITAL LETTER PHI
|
||||
0x0398, //GREEK CAPITAL LETTER THETA
|
||||
0x03a9, //GREEK CAPITAL LETTER OMEGA
|
||||
0x03b4, //GREEK SMALL LETTER DELTA
|
||||
0x221e, //INFINITY
|
||||
0x03c6, //GREEK SMALL LETTER PHI
|
||||
0x03b5, //GREEK SMALL LETTER EPSILON
|
||||
0x2229, //INTERSECTION
|
||||
0x2261, //IDENTICAL TO
|
||||
0x00b1, //PLUS-MINUS SIGN
|
||||
0x2265, //GREATER-THAN OR EQUAL TO
|
||||
0x2264, //LESS-THAN OR EQUAL TO
|
||||
0x2320, //TOP HALF INTEGRAL
|
||||
0x2321, //BOTTOM HALF INTEGRAL
|
||||
0x00f7, //DIVISION SIGN
|
||||
0x2248, //ALMOST EQUAL TO
|
||||
0x00b0, //DEGREE SIGN
|
||||
0x2219, //BULLET OPERATOR
|
||||
0x00b7, //MIDDLE DOT
|
||||
0x221a, //SQUARE ROOT
|
||||
0x207f, //SUPERSCRIPT LATIN SMALL LETTER N
|
||||
0x00b2, //SUPERSCRIPT TWO
|
||||
0x25a0, //BLACK SQUARE
|
||||
0x00a0, //NO-BREAK SPACE
|
||||
},
|
||||
}
|
|
@ -1,262 +0,0 @@
|
|||
package cp
|
||||
|
||||
var cp850 *charsetMap = &charsetMap{
|
||||
sb: [256]rune{
|
||||
0x0000, //NULL
|
||||
0x0001, //START OF HEADING
|
||||
0x0002, //START OF TEXT
|
||||
0x0003, //END OF TEXT
|
||||
0x0004, //END OF TRANSMISSION
|
||||
0x0005, //ENQUIRY
|
||||
0x0006, //ACKNOWLEDGE
|
||||
0x0007, //BELL
|
||||
0x0008, //BACKSPACE
|
||||
0x0009, //HORIZONTAL TABULATION
|
||||
0x000a, //LINE FEED
|
||||
0x000b, //VERTICAL TABULATION
|
||||
0x000c, //FORM FEED
|
||||
0x000d, //CARRIAGE RETURN
|
||||
0x000e, //SHIFT OUT
|
||||
0x000f, //SHIFT IN
|
||||
0x0010, //DATA LINK ESCAPE
|
||||
0x0011, //DEVICE CONTROL ONE
|
||||
0x0012, //DEVICE CONTROL TWO
|
||||
0x0013, //DEVICE CONTROL THREE
|
||||
0x0014, //DEVICE CONTROL FOUR
|
||||
0x0015, //NEGATIVE ACKNOWLEDGE
|
||||
0x0016, //SYNCHRONOUS IDLE
|
||||
0x0017, //END OF TRANSMISSION BLOCK
|
||||
0x0018, //CANCEL
|
||||
0x0019, //END OF MEDIUM
|
||||
0x001a, //SUBSTITUTE
|
||||
0x001b, //ESCAPE
|
||||
0x001c, //FILE SEPARATOR
|
||||
0x001d, //GROUP SEPARATOR
|
||||
0x001e, //RECORD SEPARATOR
|
||||
0x001f, //UNIT SEPARATOR
|
||||
0x0020, //SPACE
|
||||
0x0021, //EXCLAMATION MARK
|
||||
0x0022, //QUOTATION MARK
|
||||
0x0023, //NUMBER SIGN
|
||||
0x0024, //DOLLAR SIGN
|
||||
0x0025, //PERCENT SIGN
|
||||
0x0026, //AMPERSAND
|
||||
0x0027, //APOSTROPHE
|
||||
0x0028, //LEFT PARENTHESIS
|
||||
0x0029, //RIGHT PARENTHESIS
|
||||
0x002a, //ASTERISK
|
||||
0x002b, //PLUS SIGN
|
||||
0x002c, //COMMA
|
||||
0x002d, //HYPHEN-MINUS
|
||||
0x002e, //FULL STOP
|
||||
0x002f, //SOLIDUS
|
||||
0x0030, //DIGIT ZERO
|
||||
0x0031, //DIGIT ONE
|
||||
0x0032, //DIGIT TWO
|
||||
0x0033, //DIGIT THREE
|
||||
0x0034, //DIGIT FOUR
|
||||
0x0035, //DIGIT FIVE
|
||||
0x0036, //DIGIT SIX
|
||||
0x0037, //DIGIT SEVEN
|
||||
0x0038, //DIGIT EIGHT
|
||||
0x0039, //DIGIT NINE
|
||||
0x003a, //COLON
|
||||
0x003b, //SEMICOLON
|
||||
0x003c, //LESS-THAN SIGN
|
||||
0x003d, //EQUALS SIGN
|
||||
0x003e, //GREATER-THAN SIGN
|
||||
0x003f, //QUESTION MARK
|
||||
0x0040, //COMMERCIAL AT
|
||||
0x0041, //LATIN CAPITAL LETTER A
|
||||
0x0042, //LATIN CAPITAL LETTER B
|
||||
0x0043, //LATIN CAPITAL LETTER C
|
||||
0x0044, //LATIN CAPITAL LETTER D
|
||||
0x0045, //LATIN CAPITAL LETTER E
|
||||
0x0046, //LATIN CAPITAL LETTER F
|
||||
0x0047, //LATIN CAPITAL LETTER G
|
||||
0x0048, //LATIN CAPITAL LETTER H
|
||||
0x0049, //LATIN CAPITAL LETTER I
|
||||
0x004a, //LATIN CAPITAL LETTER J
|
||||
0x004b, //LATIN CAPITAL LETTER K
|
||||
0x004c, //LATIN CAPITAL LETTER L
|
||||
0x004d, //LATIN CAPITAL LETTER M
|
||||
0x004e, //LATIN CAPITAL LETTER N
|
||||
0x004f, //LATIN CAPITAL LETTER O
|
||||
0x0050, //LATIN CAPITAL LETTER P
|
||||
0x0051, //LATIN CAPITAL LETTER Q
|
||||
0x0052, //LATIN CAPITAL LETTER R
|
||||
0x0053, //LATIN CAPITAL LETTER S
|
||||
0x0054, //LATIN CAPITAL LETTER T
|
||||
0x0055, //LATIN CAPITAL LETTER U
|
||||
0x0056, //LATIN CAPITAL LETTER V
|
||||
0x0057, //LATIN CAPITAL LETTER W
|
||||
0x0058, //LATIN CAPITAL LETTER X
|
||||
0x0059, //LATIN CAPITAL LETTER Y
|
||||
0x005a, //LATIN CAPITAL LETTER Z
|
||||
0x005b, //LEFT SQUARE BRACKET
|
||||
0x005c, //REVERSE SOLIDUS
|
||||
0x005d, //RIGHT SQUARE BRACKET
|
||||
0x005e, //CIRCUMFLEX ACCENT
|
||||
0x005f, //LOW LINE
|
||||
0x0060, //GRAVE ACCENT
|
||||
0x0061, //LATIN SMALL LETTER A
|
||||
0x0062, //LATIN SMALL LETTER B
|
||||
0x0063, //LATIN SMALL LETTER C
|
||||
0x0064, //LATIN SMALL LETTER D
|
||||
0x0065, //LATIN SMALL LETTER E
|
||||
0x0066, //LATIN SMALL LETTER F
|
||||
0x0067, //LATIN SMALL LETTER G
|
||||
0x0068, //LATIN SMALL LETTER H
|
||||
0x0069, //LATIN SMALL LETTER I
|
||||
0x006a, //LATIN SMALL LETTER J
|
||||
0x006b, //LATIN SMALL LETTER K
|
||||
0x006c, //LATIN SMALL LETTER L
|
||||
0x006d, //LATIN SMALL LETTER M
|
||||
0x006e, //LATIN SMALL LETTER N
|
||||
0x006f, //LATIN SMALL LETTER O
|
||||
0x0070, //LATIN SMALL LETTER P
|
||||
0x0071, //LATIN SMALL LETTER Q
|
||||
0x0072, //LATIN SMALL LETTER R
|
||||
0x0073, //LATIN SMALL LETTER S
|
||||
0x0074, //LATIN SMALL LETTER T
|
||||
0x0075, //LATIN SMALL LETTER U
|
||||
0x0076, //LATIN SMALL LETTER V
|
||||
0x0077, //LATIN SMALL LETTER W
|
||||
0x0078, //LATIN SMALL LETTER X
|
||||
0x0079, //LATIN SMALL LETTER Y
|
||||
0x007a, //LATIN SMALL LETTER Z
|
||||
0x007b, //LEFT CURLY BRACKET
|
||||
0x007c, //VERTICAL LINE
|
||||
0x007d, //RIGHT CURLY BRACKET
|
||||
0x007e, //TILDE
|
||||
0x007f, //DELETE
|
||||
0x00c7, //LATIN CAPITAL LETTER C WITH CEDILLA
|
||||
0x00fc, //LATIN SMALL LETTER U WITH DIAERESIS
|
||||
0x00e9, //LATIN SMALL LETTER E WITH ACUTE
|
||||
0x00e2, //LATIN SMALL LETTER A WITH CIRCUMFLEX
|
||||
0x00e4, //LATIN SMALL LETTER A WITH DIAERESIS
|
||||
0x00e0, //LATIN SMALL LETTER A WITH GRAVE
|
||||
0x00e5, //LATIN SMALL LETTER A WITH RING ABOVE
|
||||
0x00e7, //LATIN SMALL LETTER C WITH CEDILLA
|
||||
0x00ea, //LATIN SMALL LETTER E WITH CIRCUMFLEX
|
||||
0x00eb, //LATIN SMALL LETTER E WITH DIAERESIS
|
||||
0x00e8, //LATIN SMALL LETTER E WITH GRAVE
|
||||
0x00ef, //LATIN SMALL LETTER I WITH DIAERESIS
|
||||
0x00ee, //LATIN SMALL LETTER I WITH CIRCUMFLEX
|
||||
0x00ec, //LATIN SMALL LETTER I WITH GRAVE
|
||||
0x00c4, //LATIN CAPITAL LETTER A WITH DIAERESIS
|
||||
0x00c5, //LATIN CAPITAL LETTER A WITH RING ABOVE
|
||||
0x00c9, //LATIN CAPITAL LETTER E WITH ACUTE
|
||||
0x00e6, //LATIN SMALL LIGATURE AE
|
||||
0x00c6, //LATIN CAPITAL LIGATURE AE
|
||||
0x00f4, //LATIN SMALL LETTER O WITH CIRCUMFLEX
|
||||
0x00f6, //LATIN SMALL LETTER O WITH DIAERESIS
|
||||
0x00f2, //LATIN SMALL LETTER O WITH GRAVE
|
||||
0x00fb, //LATIN SMALL LETTER U WITH CIRCUMFLEX
|
||||
0x00f9, //LATIN SMALL LETTER U WITH GRAVE
|
||||
0x00ff, //LATIN SMALL LETTER Y WITH DIAERESIS
|
||||
0x00d6, //LATIN CAPITAL LETTER O WITH DIAERESIS
|
||||
0x00dc, //LATIN CAPITAL LETTER U WITH DIAERESIS
|
||||
0x00f8, //LATIN SMALL LETTER O WITH STROKE
|
||||
0x00a3, //POUND SIGN
|
||||
0x00d8, //LATIN CAPITAL LETTER O WITH STROKE
|
||||
0x00d7, //MULTIPLICATION SIGN
|
||||
0x0192, //LATIN SMALL LETTER F WITH HOOK
|
||||
0x00e1, //LATIN SMALL LETTER A WITH ACUTE
|
||||
0x00ed, //LATIN SMALL LETTER I WITH ACUTE
|
||||
0x00f3, //LATIN SMALL LETTER O WITH ACUTE
|
||||
0x00fa, //LATIN SMALL LETTER U WITH ACUTE
|
||||
0x00f1, //LATIN SMALL LETTER N WITH TILDE
|
||||
0x00d1, //LATIN CAPITAL LETTER N WITH TILDE
|
||||
0x00aa, //FEMININE ORDINAL INDICATOR
|
||||
0x00ba, //MASCULINE ORDINAL INDICATOR
|
||||
0x00bf, //INVERTED QUESTION MARK
|
||||
0x00ae, //REGISTERED SIGN
|
||||
0x00ac, //NOT SIGN
|
||||
0x00bd, //VULGAR FRACTION ONE HALF
|
||||
0x00bc, //VULGAR FRACTION ONE QUARTER
|
||||
0x00a1, //INVERTED EXCLAMATION MARK
|
||||
0x00ab, //LEFT-POINTING DOUBLE ANGLE QUOTATION MARK
|
||||
0x00bb, //RIGHT-POINTING DOUBLE ANGLE QUOTATION MARK
|
||||
0x2591, //LIGHT SHADE
|
||||
0x2592, //MEDIUM SHADE
|
||||
0x2593, //DARK SHADE
|
||||
0x2502, //BOX DRAWINGS LIGHT VERTICAL
|
||||
0x2524, //BOX DRAWINGS LIGHT VERTICAL AND LEFT
|
||||
0x00c1, //LATIN CAPITAL LETTER A WITH ACUTE
|
||||
0x00c2, //LATIN CAPITAL LETTER A WITH CIRCUMFLEX
|
||||
0x00c0, //LATIN CAPITAL LETTER A WITH GRAVE
|
||||
0x00a9, //COPYRIGHT SIGN
|
||||
0x2563, //BOX DRAWINGS DOUBLE VERTICAL AND LEFT
|
||||
0x2551, //BOX DRAWINGS DOUBLE VERTICAL
|
||||
0x2557, //BOX DRAWINGS DOUBLE DOWN AND LEFT
|
||||
0x255d, //BOX DRAWINGS DOUBLE UP AND LEFT
|
||||
0x00a2, //CENT SIGN
|
||||
0x00a5, //YEN SIGN
|
||||
0x2510, //BOX DRAWINGS LIGHT DOWN AND LEFT
|
||||
0x2514, //BOX DRAWINGS LIGHT UP AND RIGHT
|
||||
0x2534, //BOX DRAWINGS LIGHT UP AND HORIZONTAL
|
||||
0x252c, //BOX DRAWINGS LIGHT DOWN AND HORIZONTAL
|
||||
0x251c, //BOX DRAWINGS LIGHT VERTICAL AND RIGHT
|
||||
0x2500, //BOX DRAWINGS LIGHT HORIZONTAL
|
||||
0x253c, //BOX DRAWINGS LIGHT VERTICAL AND HORIZONTAL
|
||||
0x00e3, //LATIN SMALL LETTER A WITH TILDE
|
||||
0x00c3, //LATIN CAPITAL LETTER A WITH TILDE
|
||||
0x255a, //BOX DRAWINGS DOUBLE UP AND RIGHT
|
||||
0x2554, //BOX DRAWINGS DOUBLE DOWN AND RIGHT
|
||||
0x2569, //BOX DRAWINGS DOUBLE UP AND HORIZONTAL
|
||||
0x2566, //BOX DRAWINGS DOUBLE DOWN AND HORIZONTAL
|
||||
0x2560, //BOX DRAWINGS DOUBLE VERTICAL AND RIGHT
|
||||
0x2550, //BOX DRAWINGS DOUBLE HORIZONTAL
|
||||
0x256c, //BOX DRAWINGS DOUBLE VERTICAL AND HORIZONTAL
|
||||
0x00a4, //CURRENCY SIGN
|
||||
0x00f0, //LATIN SMALL LETTER ETH
|
||||
0x00d0, //LATIN CAPITAL LETTER ETH
|
||||
0x00ca, //LATIN CAPITAL LETTER E WITH CIRCUMFLEX
|
||||
0x00cb, //LATIN CAPITAL LETTER E WITH DIAERESIS
|
||||
0x00c8, //LATIN CAPITAL LETTER E WITH GRAVE
|
||||
0x0131, //LATIN SMALL LETTER DOTLESS I
|
||||
0x00cd, //LATIN CAPITAL LETTER I WITH ACUTE
|
||||
0x00ce, //LATIN CAPITAL LETTER I WITH CIRCUMFLEX
|
||||
0x00cf, //LATIN CAPITAL LETTER I WITH DIAERESIS
|
||||
0x2518, //BOX DRAWINGS LIGHT UP AND LEFT
|
||||
0x250c, //BOX DRAWINGS LIGHT DOWN AND RIGHT
|
||||
0x2588, //FULL BLOCK
|
||||
0x2584, //LOWER HALF BLOCK
|
||||
0x00a6, //BROKEN BAR
|
||||
0x00cc, //LATIN CAPITAL LETTER I WITH GRAVE
|
||||
0x2580, //UPPER HALF BLOCK
|
||||
0x00d3, //LATIN CAPITAL LETTER O WITH ACUTE
|
||||
0x00df, //LATIN SMALL LETTER SHARP S
|
||||
0x00d4, //LATIN CAPITAL LETTER O WITH CIRCUMFLEX
|
||||
0x00d2, //LATIN CAPITAL LETTER O WITH GRAVE
|
||||
0x00f5, //LATIN SMALL LETTER O WITH TILDE
|
||||
0x00d5, //LATIN CAPITAL LETTER O WITH TILDE
|
||||
0x00b5, //MICRO SIGN
|
||||
0x00fe, //LATIN SMALL LETTER THORN
|
||||
0x00de, //LATIN CAPITAL LETTER THORN
|
||||
0x00da, //LATIN CAPITAL LETTER U WITH ACUTE
|
||||
0x00db, //LATIN CAPITAL LETTER U WITH CIRCUMFLEX
|
||||
0x00d9, //LATIN CAPITAL LETTER U WITH GRAVE
|
||||
0x00fd, //LATIN SMALL LETTER Y WITH ACUTE
|
||||
0x00dd, //LATIN CAPITAL LETTER Y WITH ACUTE
|
||||
0x00af, //MACRON
|
||||
0x00b4, //ACUTE ACCENT
|
||||
0x00ad, //SOFT HYPHEN
|
||||
0x00b1, //PLUS-MINUS SIGN
|
||||
0x2017, //DOUBLE LOW LINE
|
||||
0x00be, //VULGAR FRACTION THREE QUARTERS
|
||||
0x00b6, //PILCROW SIGN
|
||||
0x00a7, //SECTION SIGN
|
||||
0x00f7, //DIVISION SIGN
|
||||
0x00b8, //CEDILLA
|
||||
0x00b0, //DEGREE SIGN
|
||||
0x00a8, //DIAERESIS
|
||||
0x00b7, //MIDDLE DOT
|
||||
0x00b9, //SUPERSCRIPT ONE
|
||||
0x00b3, //SUPERSCRIPT THREE
|
||||
0x00b2, //SUPERSCRIPT TWO
|
||||
0x25a0, //BLACK SQUARE
|
||||
0x00a0, //NO-BREAK SPACE
|
||||
},
|
||||
}
|
|
@ -1,262 +0,0 @@
|
|||
package cp
|
||||
|
||||
var cp874 *charsetMap = &charsetMap{
|
||||
sb: [256]rune{
|
||||
0x0000, //NULL
|
||||
0x0001, //START OF HEADING
|
||||
0x0002, //START OF TEXT
|
||||
0x0003, //END OF TEXT
|
||||
0x0004, //END OF TRANSMISSION
|
||||
0x0005, //ENQUIRY
|
||||
0x0006, //ACKNOWLEDGE
|
||||
0x0007, //BELL
|
||||
0x0008, //BACKSPACE
|
||||
0x0009, //HORIZONTAL TABULATION
|
||||
0x000A, //LINE FEED
|
||||
0x000B, //VERTICAL TABULATION
|
||||
0x000C, //FORM FEED
|
||||
0x000D, //CARRIAGE RETURN
|
||||
0x000E, //SHIFT OUT
|
||||
0x000F, //SHIFT IN
|
||||
0x0010, //DATA LINK ESCAPE
|
||||
0x0011, //DEVICE CONTROL ONE
|
||||
0x0012, //DEVICE CONTROL TWO
|
||||
0x0013, //DEVICE CONTROL THREE
|
||||
0x0014, //DEVICE CONTROL FOUR
|
||||
0x0015, //NEGATIVE ACKNOWLEDGE
|
||||
0x0016, //SYNCHRONOUS IDLE
|
||||
0x0017, //END OF TRANSMISSION BLOCK
|
||||
0x0018, //CANCEL
|
||||
0x0019, //END OF MEDIUM
|
||||
0x001A, //SUBSTITUTE
|
||||
0x001B, //ESCAPE
|
||||
0x001C, //FILE SEPARATOR
|
||||
0x001D, //GROUP SEPARATOR
|
||||
0x001E, //RECORD SEPARATOR
|
||||
0x001F, //UNIT SEPARATOR
|
||||
0x0020, //SPACE
|
||||
0x0021, //EXCLAMATION MARK
|
||||
0x0022, //QUOTATION MARK
|
||||
0x0023, //NUMBER SIGN
|
||||
0x0024, //DOLLAR SIGN
|
||||
0x0025, //PERCENT SIGN
|
||||
0x0026, //AMPERSAND
|
||||
0x0027, //APOSTROPHE
|
||||
0x0028, //LEFT PARENTHESIS
|
||||
0x0029, //RIGHT PARENTHESIS
|
||||
0x002A, //ASTERISK
|
||||
0x002B, //PLUS SIGN
|
||||
0x002C, //COMMA
|
||||
0x002D, //HYPHEN-MINUS
|
||||
0x002E, //FULL STOP
|
||||
0x002F, //SOLIDUS
|
||||
0x0030, //DIGIT ZERO
|
||||
0x0031, //DIGIT ONE
|
||||
0x0032, //DIGIT TWO
|
||||
0x0033, //DIGIT THREE
|
||||
0x0034, //DIGIT FOUR
|
||||
0x0035, //DIGIT FIVE
|
||||
0x0036, //DIGIT SIX
|
||||
0x0037, //DIGIT SEVEN
|
||||
0x0038, //DIGIT EIGHT
|
||||
0x0039, //DIGIT NINE
|
||||
0x003A, //COLON
|
||||
0x003B, //SEMICOLON
|
||||
0x003C, //LESS-THAN SIGN
|
||||
0x003D, //EQUALS SIGN
|
||||
0x003E, //GREATER-THAN SIGN
|
||||
0x003F, //QUESTION MARK
|
||||
0x0040, //COMMERCIAL AT
|
||||
0x0041, //LATIN CAPITAL LETTER A
|
||||
0x0042, //LATIN CAPITAL LETTER B
|
||||
0x0043, //LATIN CAPITAL LETTER C
|
||||
0x0044, //LATIN CAPITAL LETTER D
|
||||
0x0045, //LATIN CAPITAL LETTER E
|
||||
0x0046, //LATIN CAPITAL LETTER F
|
||||
0x0047, //LATIN CAPITAL LETTER G
|
||||
0x0048, //LATIN CAPITAL LETTER H
|
||||
0x0049, //LATIN CAPITAL LETTER I
|
||||
0x004A, //LATIN CAPITAL LETTER J
|
||||
0x004B, //LATIN CAPITAL LETTER K
|
||||
0x004C, //LATIN CAPITAL LETTER L
|
||||
0x004D, //LATIN CAPITAL LETTER M
|
||||
0x004E, //LATIN CAPITAL LETTER N
|
||||
0x004F, //LATIN CAPITAL LETTER O
|
||||
0x0050, //LATIN CAPITAL LETTER P
|
||||
0x0051, //LATIN CAPITAL LETTER Q
|
||||
0x0052, //LATIN CAPITAL LETTER R
|
||||
0x0053, //LATIN CAPITAL LETTER S
|
||||
0x0054, //LATIN CAPITAL LETTER T
|
||||
0x0055, //LATIN CAPITAL LETTER U
|
||||
0x0056, //LATIN CAPITAL LETTER V
|
||||
0x0057, //LATIN CAPITAL LETTER W
|
||||
0x0058, //LATIN CAPITAL LETTER X
|
||||
0x0059, //LATIN CAPITAL LETTER Y
|
||||
0x005A, //LATIN CAPITAL LETTER Z
|
||||
0x005B, //LEFT SQUARE BRACKET
|
||||
0x005C, //REVERSE SOLIDUS
|
||||
0x005D, //RIGHT SQUARE BRACKET
|
||||
0x005E, //CIRCUMFLEX ACCENT
|
||||
0x005F, //LOW LINE
|
||||
0x0060, //GRAVE ACCENT
|
||||
0x0061, //LATIN SMALL LETTER A
|
||||
0x0062, //LATIN SMALL LETTER B
|
||||
0x0063, //LATIN SMALL LETTER C
|
||||
0x0064, //LATIN SMALL LETTER D
|
||||
0x0065, //LATIN SMALL LETTER E
|
||||
0x0066, //LATIN SMALL LETTER F
|
||||
0x0067, //LATIN SMALL LETTER G
|
||||
0x0068, //LATIN SMALL LETTER H
|
||||
0x0069, //LATIN SMALL LETTER I
|
||||
0x006A, //LATIN SMALL LETTER J
|
||||
0x006B, //LATIN SMALL LETTER K
|
||||
0x006C, //LATIN SMALL LETTER L
|
||||
0x006D, //LATIN SMALL LETTER M
|
||||
0x006E, //LATIN SMALL LETTER N
|
||||
0x006F, //LATIN SMALL LETTER O
|
||||
0x0070, //LATIN SMALL LETTER P
|
||||
0x0071, //LATIN SMALL LETTER Q
|
||||
0x0072, //LATIN SMALL LETTER R
|
||||
0x0073, //LATIN SMALL LETTER S
|
||||
0x0074, //LATIN SMALL LETTER T
|
||||
0x0075, //LATIN SMALL LETTER U
|
||||
0x0076, //LATIN SMALL LETTER V
|
||||
0x0077, //LATIN SMALL LETTER W
|
||||
0x0078, //LATIN SMALL LETTER X
|
||||
0x0079, //LATIN SMALL LETTER Y
|
||||
0x007A, //LATIN SMALL LETTER Z
|
||||
0x007B, //LEFT CURLY BRACKET
|
||||
0x007C, //VERTICAL LINE
|
||||
0x007D, //RIGHT CURLY BRACKET
|
||||
0x007E, //TILDE
|
||||
0x007F, //DELETE
|
||||
0x20AC, //EURO SIGN
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0x2026, //HORIZONTAL ELLIPSIS
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0x2018, //LEFT SINGLE QUOTATION MARK
|
||||
0x2019, //RIGHT SINGLE QUOTATION MARK
|
||||
0x201C, //LEFT DOUBLE QUOTATION MARK
|
||||
0x201D, //RIGHT DOUBLE QUOTATION MARK
|
||||
0x2022, //BULLET
|
||||
0x2013, //EN DASH
|
||||
0x2014, //EM DASH
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0x00A0, //NO-BREAK SPACE
|
||||
0x0E01, //THAI CHARACTER KO KAI
|
||||
0x0E02, //THAI CHARACTER KHO KHAI
|
||||
0x0E03, //THAI CHARACTER KHO KHUAT
|
||||
0x0E04, //THAI CHARACTER KHO KHWAI
|
||||
0x0E05, //THAI CHARACTER KHO KHON
|
||||
0x0E06, //THAI CHARACTER KHO RAKHANG
|
||||
0x0E07, //THAI CHARACTER NGO NGU
|
||||
0x0E08, //THAI CHARACTER CHO CHAN
|
||||
0x0E09, //THAI CHARACTER CHO CHING
|
||||
0x0E0A, //THAI CHARACTER CHO CHANG
|
||||
0x0E0B, //THAI CHARACTER SO SO
|
||||
0x0E0C, //THAI CHARACTER CHO CHOE
|
||||
0x0E0D, //THAI CHARACTER YO YING
|
||||
0x0E0E, //THAI CHARACTER DO CHADA
|
||||
0x0E0F, //THAI CHARACTER TO PATAK
|
||||
0x0E10, //THAI CHARACTER THO THAN
|
||||
0x0E11, //THAI CHARACTER THO NANGMONTHO
|
||||
0x0E12, //THAI CHARACTER THO PHUTHAO
|
||||
0x0E13, //THAI CHARACTER NO NEN
|
||||
0x0E14, //THAI CHARACTER DO DEK
|
||||
0x0E15, //THAI CHARACTER TO TAO
|
||||
0x0E16, //THAI CHARACTER THO THUNG
|
||||
0x0E17, //THAI CHARACTER THO THAHAN
|
||||
0x0E18, //THAI CHARACTER THO THONG
|
||||
0x0E19, //THAI CHARACTER NO NU
|
||||
0x0E1A, //THAI CHARACTER BO BAIMAI
|
||||
0x0E1B, //THAI CHARACTER PO PLA
|
||||
0x0E1C, //THAI CHARACTER PHO PHUNG
|
||||
0x0E1D, //THAI CHARACTER FO FA
|
||||
0x0E1E, //THAI CHARACTER PHO PHAN
|
||||
0x0E1F, //THAI CHARACTER FO FAN
|
||||
0x0E20, //THAI CHARACTER PHO SAMPHAO
|
||||
0x0E21, //THAI CHARACTER MO MA
|
||||
0x0E22, //THAI CHARACTER YO YAK
|
||||
0x0E23, //THAI CHARACTER RO RUA
|
||||
0x0E24, //THAI CHARACTER RU
|
||||
0x0E25, //THAI CHARACTER LO LING
|
||||
0x0E26, //THAI CHARACTER LU
|
||||
0x0E27, //THAI CHARACTER WO WAEN
|
||||
0x0E28, //THAI CHARACTER SO SALA
|
||||
0x0E29, //THAI CHARACTER SO RUSI
|
||||
0x0E2A, //THAI CHARACTER SO SUA
|
||||
0x0E2B, //THAI CHARACTER HO HIP
|
||||
0x0E2C, //THAI CHARACTER LO CHULA
|
||||
0x0E2D, //THAI CHARACTER O ANG
|
||||
0x0E2E, //THAI CHARACTER HO NOKHUK
|
||||
0x0E2F, //THAI CHARACTER PAIYANNOI
|
||||
0x0E30, //THAI CHARACTER SARA A
|
||||
0x0E31, //THAI CHARACTER MAI HAN-AKAT
|
||||
0x0E32, //THAI CHARACTER SARA AA
|
||||
0x0E33, //THAI CHARACTER SARA AM
|
||||
0x0E34, //THAI CHARACTER SARA I
|
||||
0x0E35, //THAI CHARACTER SARA II
|
||||
0x0E36, //THAI CHARACTER SARA UE
|
||||
0x0E37, //THAI CHARACTER SARA UEE
|
||||
0x0E38, //THAI CHARACTER SARA U
|
||||
0x0E39, //THAI CHARACTER SARA UU
|
||||
0x0E3A, //THAI CHARACTER PHINTHU
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0x0E3F, //THAI CURRENCY SYMBOL BAHT
|
||||
0x0E40, //THAI CHARACTER SARA E
|
||||
0x0E41, //THAI CHARACTER SARA AE
|
||||
0x0E42, //THAI CHARACTER SARA O
|
||||
0x0E43, //THAI CHARACTER SARA AI MAIMUAN
|
||||
0x0E44, //THAI CHARACTER SARA AI MAIMALAI
|
||||
0x0E45, //THAI CHARACTER LAKKHANGYAO
|
||||
0x0E46, //THAI CHARACTER MAIYAMOK
|
||||
0x0E47, //THAI CHARACTER MAITAIKHU
|
||||
0x0E48, //THAI CHARACTER MAI EK
|
||||
0x0E49, //THAI CHARACTER MAI THO
|
||||
0x0E4A, //THAI CHARACTER MAI TRI
|
||||
0x0E4B, //THAI CHARACTER MAI CHATTAWA
|
||||
0x0E4C, //THAI CHARACTER THANTHAKHAT
|
||||
0x0E4D, //THAI CHARACTER NIKHAHIT
|
||||
0x0E4E, //THAI CHARACTER YAMAKKAN
|
||||
0x0E4F, //THAI CHARACTER FONGMAN
|
||||
0x0E50, //THAI DIGIT ZERO
|
||||
0x0E51, //THAI DIGIT ONE
|
||||
0x0E52, //THAI DIGIT TWO
|
||||
0x0E53, //THAI DIGIT THREE
|
||||
0x0E54, //THAI DIGIT FOUR
|
||||
0x0E55, //THAI DIGIT FIVE
|
||||
0x0E56, //THAI DIGIT SIX
|
||||
0x0E57, //THAI DIGIT SEVEN
|
||||
0x0E58, //THAI DIGIT EIGHT
|
||||
0x0E59, //THAI DIGIT NINE
|
||||
0x0E5A, //THAI CHARACTER ANGKHANKHU
|
||||
0x0E5B, //THAI CHARACTER KHOMUT
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
0xFFFD, //UNDEFINED
|
||||
},
|
||||
}
|
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
|
@ -1,265 +0,0 @@
|
|||
// Package querytext is the old query parser and parameter substitute process.
|
||||
// Do not use on new code.
|
||||
//
|
||||
// This package is not subject to any API compatibility guarantee.
|
||||
package querytext
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"io"
|
||||
"strconv"
|
||||
)
|
||||
|
||||
type parser struct {
|
||||
r *bytes.Reader
|
||||
w bytes.Buffer
|
||||
paramCount int
|
||||
paramMax int
|
||||
|
||||
// using map as a set
|
||||
namedParams map[string]bool
|
||||
}
|
||||
|
||||
func (p *parser) next() (rune, bool) {
|
||||
ch, _, err := p.r.ReadRune()
|
||||
if err != nil {
|
||||
if err != io.EOF {
|
||||
panic(err)
|
||||
}
|
||||
return 0, false
|
||||
}
|
||||
return ch, true
|
||||
}
|
||||
|
||||
func (p *parser) unread() {
|
||||
err := p.r.UnreadRune()
|
||||
if err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
||||
|
||||
func (p *parser) write(ch rune) {
|
||||
p.w.WriteRune(ch)
|
||||
}
|
||||
|
||||
type stateFunc func(*parser) stateFunc
|
||||
|
||||
// ParseParams rewrites the query from using "?" placeholders
|
||||
// to using "@pN" parameter names that SQL Server will accept.
|
||||
//
|
||||
// This function and package is not subject to any API compatibility guarantee.
|
||||
func ParseParams(query string) (string, int) {
|
||||
p := &parser{
|
||||
r: bytes.NewReader([]byte(query)),
|
||||
namedParams: map[string]bool{},
|
||||
}
|
||||
state := parseNormal
|
||||
for state != nil {
|
||||
state = state(p)
|
||||
}
|
||||
return p.w.String(), p.paramMax + len(p.namedParams)
|
||||
}
|
||||
|
||||
func parseNormal(p *parser) stateFunc {
|
||||
for {
|
||||
ch, ok := p.next()
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
if ch == '?' {
|
||||
return parseOrdinalParameter
|
||||
} else if ch == '$' || ch == ':' {
|
||||
ch2, ok := p.next()
|
||||
if !ok {
|
||||
p.write(ch)
|
||||
return nil
|
||||
}
|
||||
p.unread()
|
||||
if ch2 >= '0' && ch2 <= '9' {
|
||||
return parseOrdinalParameter
|
||||
} else if 'a' <= ch2 && ch2 <= 'z' || 'A' <= ch2 && ch2 <= 'Z' {
|
||||
return parseNamedParameter
|
||||
}
|
||||
}
|
||||
p.write(ch)
|
||||
switch ch {
|
||||
case '\'':
|
||||
return parseQuote
|
||||
case '"':
|
||||
return parseDoubleQuote
|
||||
case '[':
|
||||
return parseBracket
|
||||
case '-':
|
||||
return parseLineComment
|
||||
case '/':
|
||||
return parseComment
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func parseOrdinalParameter(p *parser) stateFunc {
|
||||
var paramN int
|
||||
var ok bool
|
||||
for {
|
||||
var ch rune
|
||||
ch, ok = p.next()
|
||||
if ok && ch >= '0' && ch <= '9' {
|
||||
paramN = paramN*10 + int(ch-'0')
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
if ok {
|
||||
p.unread()
|
||||
}
|
||||
if paramN == 0 {
|
||||
p.paramCount++
|
||||
paramN = p.paramCount
|
||||
}
|
||||
if paramN > p.paramMax {
|
||||
p.paramMax = paramN
|
||||
}
|
||||
p.w.WriteString("@p")
|
||||
p.w.WriteString(strconv.Itoa(paramN))
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
return parseNormal
|
||||
}
|
||||
|
||||
func parseNamedParameter(p *parser) stateFunc {
|
||||
var paramName string
|
||||
var ok bool
|
||||
for {
|
||||
var ch rune
|
||||
ch, ok = p.next()
|
||||
if ok && (ch >= '0' && ch <= '9' || 'a' <= ch && ch <= 'z' || 'A' <= ch && ch <= 'Z') {
|
||||
paramName = paramName + string(ch)
|
||||
} else {
|
||||
break
|
||||
}
|
||||
}
|
||||
if ok {
|
||||
p.unread()
|
||||
}
|
||||
p.namedParams[paramName] = true
|
||||
p.w.WriteString("@")
|
||||
p.w.WriteString(paramName)
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
return parseNormal
|
||||
}
|
||||
|
||||
func parseQuote(p *parser) stateFunc {
|
||||
for {
|
||||
ch, ok := p.next()
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
p.write(ch)
|
||||
if ch == '\'' {
|
||||
return parseNormal
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func parseDoubleQuote(p *parser) stateFunc {
|
||||
for {
|
||||
ch, ok := p.next()
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
p.write(ch)
|
||||
if ch == '"' {
|
||||
return parseNormal
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func parseBracket(p *parser) stateFunc {
|
||||
for {
|
||||
ch, ok := p.next()
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
p.write(ch)
|
||||
if ch == ']' {
|
||||
ch, ok = p.next()
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
if ch != ']' {
|
||||
p.unread()
|
||||
return parseNormal
|
||||
}
|
||||
p.write(ch)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func parseLineComment(p *parser) stateFunc {
|
||||
ch, ok := p.next()
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
if ch != '-' {
|
||||
p.unread()
|
||||
return parseNormal
|
||||
}
|
||||
p.write(ch)
|
||||
for {
|
||||
ch, ok = p.next()
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
p.write(ch)
|
||||
if ch == '\n' {
|
||||
return parseNormal
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func parseComment(p *parser) stateFunc {
|
||||
var nested int
|
||||
ch, ok := p.next()
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
if ch != '*' {
|
||||
p.unread()
|
||||
return parseNormal
|
||||
}
|
||||
p.write(ch)
|
||||
for {
|
||||
ch, ok = p.next()
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
p.write(ch)
|
||||
for ch == '*' {
|
||||
ch, ok = p.next()
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
p.write(ch)
|
||||
if ch == '/' {
|
||||
if nested == 0 {
|
||||
return parseNormal
|
||||
} else {
|
||||
nested--
|
||||
}
|
||||
}
|
||||
}
|
||||
for ch == '/' {
|
||||
ch, ok = p.next()
|
||||
if !ok {
|
||||
return nil
|
||||
}
|
||||
p.write(ch)
|
||||
if ch == '*' {
|
||||
nested++
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,30 +0,0 @@
|
|||
package mssql
|
||||
|
||||
import (
|
||||
"log"
|
||||
)
|
||||
|
||||
type Logger interface {
|
||||
Printf(format string, v ...interface{})
|
||||
Println(v ...interface{})
|
||||
}
|
||||
|
||||
type optionalLogger struct {
|
||||
logger Logger
|
||||
}
|
||||
|
||||
func (o optionalLogger) Printf(format string, v ...interface{}) {
|
||||
if o.logger != nil {
|
||||
o.logger.Printf(format, v...)
|
||||
} else {
|
||||
log.Printf(format, v...)
|
||||
}
|
||||
}
|
||||
|
||||
func (o optionalLogger) Println(v ...interface{}) {
|
||||
if o.logger != nil {
|
||||
o.logger.Println(v...)
|
||||
} else {
|
||||
log.Println(v...)
|
||||
}
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue