FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
src-cli/schema/stringdata.go at 3.11.2 · sourcegraph/src-cli · GitHub
Uh oh!
There was an error while loading.
Please reload this page
.
sourcegraph
/
src-cli
Public
Notifications
You must be signed in to change notification settings
Fork
76
Star
353
Code
Issues
4
Pull requests
11
Actions
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Security and quality
Insights
Expand file tree
Breadcrumbs
src-cli
/
schema
/
stringdata.go
Copy path
More file actions
More file actions
Latest commit
History
History
History
51 lines (43 loc) · 1.12 KB
Breadcrumbs
src-cli
/
schema
/
stringdata.go
Copy path
File metadata and controls
51 lines (43 loc) · 1.12 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
// +build ignore
package
main
import
(
"flag"
"fmt"
"io/ioutil"
"os"
"strings"
)
var
(
inputFile
=
flag
.
String
(
"i"
,
""
,
"input file"
)
outputFile
=
flag
.
String
(
"o"
,
""
,
"output file"
)
constName
=
flag
.
String
(
"name"
,
"stringdata"
,
"name of Go const"
)
pkgName
=
flag
.
String
(
"pkg"
,
"main"
,
"Go package name"
)
)
func
main
() {
flag
.
Parse
()
if
*
inputFile
==
""
||
*
outputFile
==
""
{
flag
.
Usage
()
os
.
Exit
(
1
)
}
data
,
err
:=
ioutil
.
ReadFile
(
*
inputFile
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
err
)
os
.
Exit
(
1
)
}
output
,
err
:=
os
.
Create
(
*
outputFile
)
if
err
!=
nil
{
fmt
.
Fprintln
(
os
.
Stderr
,
err
)
os
.
Exit
(
1
)
}
defer
output
.
Close
()
fmt
.
Fprintln
(
output
,
"// Code generated by stringdata. DO NOT EDIT."
)
fmt
.
Fprintln
(
output
)
fmt
.
Fprintf
(
output
,
"package %s
\n
"
,
*
pkgName
)
fmt
.
Fprintln
(
output
)
fmt
.
Fprintf
(
output
,
"// %s is the content of the file %q.
\n
"
,
*
constName
,
*
inputFile
)
fmt
.
Fprintf
(
output
,
"const %s = %s"
,
*
constName
,
backtickStringLiteral
(
string
(
data
)))
fmt
.
Fprintln
(
output
)
}
func
backtickStringLiteral
(
data
string
)
string
{
return
"`"
+
strings
.
Replace
(
data
,
"`"
,
"` +
\"
`
\"
+ `"
,
-
1
)
+
"`"
}
Back
|
FazBrowse Home
|
New Git URL