-
Notifications
You must be signed in to change notification settings - Fork 15
/
Copy pathinfo.go
72 lines (54 loc) · 1.79 KB
/
info.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
// SPDX-FileCopyrightText: 2021 SAP SE
// SPDX-FileCopyrightText: 2022 SAP SE
// SPDX-FileCopyrightText: 2023 SAP SE
//
// SPDX-License-Identifier: Apache-2.0
package ase
import (
"flag"
"fmt"
"github.com/SAP/go-dblib/dsn"
"github.com/SAP/go-dblib/tds"
)
type Info struct {
tds.Info
AppName string `json:"appname" doc:"Application Name to transmit to ASE"`
NoQueryCursor bool `json:"no-query-cursor" doc:"Prevents the use of cursors for database/sql query methods. See README for details."`
CursorCacheRows int `json:"cursor-cache-rows" doc:"How many rows to cache at once when reading the result set of a cursor"`
}
// NewInfo returns a bare Info for github.com/SAP/go-dblib/dsn with defaults.
func NewInfo() (*Info, error) {
info := new(Info)
if err := tds.SetInfo(&info.Info); err != nil {
return nil, fmt.Errorf("ase: error setting TDS defaults on info: %w", err)
}
info.AppName = "github.com/SAP/go-ase"
info.CursorCacheRows = 1000
return info, nil
}
// NewInfoWithEnv is a convenience function returning an Info with
// values filled from the environment with the prefix 'ASE'.
func NewInfoWithEnv() (*Info, error) {
info, err := NewInfo()
if err != nil {
return nil, err
}
if err := dsn.FromEnv("ASE", info); err != nil {
return nil, fmt.Errorf("ase: error setting environment values on info: %w", err)
}
return info, nil
}
// NewInfoFlags is a convenience function returning an Info filled with
// defaults and a flagset with flags bound to the members of the
// returned info.
func NewInfoWithFlags() (*Info, *flag.FlagSet, error) {
info, err := NewInfo()
if err != nil {
return nil, nil, err
}
flagset, err := dsn.FlagSet("", flag.ContinueOnError, info)
if err != nil {
return nil, nil, fmt.Errorf("ase: error creating flagset: %w", err)
}
return info, flagset, nil
}