-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
62 lines (54 loc) · 1.04 KB
/
main.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
package main
import (
"bufio"
"fmt"
"os"
"strings"
)
func sqlQueryAddQuotes(valueType int) string {
keywords := readKeywords()
if len(keywords) == 0 {
return "you don't input any keyword"
}
keyList := make([]string, len(keywords))
i := 0
for keyword := range keywords {
keyList[i] = "\"" + keyword + "\""
i++
}
res := "in ("
res += strings.Join(keyList, ", ")
res += ")"
if valueType == valueTypeOther {
res = strings.ReplaceAll(res, "\"", "")
}
return res
}
func readKeywords() map[string]int {
keywords := make(map[string]int)
scanner := bufio.NewScanner(os.Stdin)
for scanner.Scan() {
line := scanner.Text()
for _, word := range strings.Fields(line) {
if strings.TrimSpace(word) == "" {
continue
}
keywords[word] = 1
}
}
return keywords
}
const valueTypeString = 0
const valueTypeOther = 1
func main() {
arg := "string"
if len(os.Args) == 2 {
arg = os.Args[1]
}
valueType := valueTypeString
if arg != "string" {
valueType = valueTypeOther
}
res := sqlQueryAddQuotes(valueType)
fmt.Println(res)
}