本文整理匯總了Golang中github.com/MakeNowJust/heredoc.Doc函數的典型用法代碼示例。如果您正苦於以下問題:Golang Doc函數的具體用法?Golang Doc怎麽用?Golang Doc使用的例子?那麽, 這裏精選的函數代碼示例或許可以為您提供幫助。
在下文中一共展示了Doc函數的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Golang代碼示例。
示例1: TestDoc
func TestDoc(t *testing.T) {
for i, test := range tests {
result := heredoc.Doc(test.raw)
if result != test.expect {
t.Errorf("tests[%d] failed: expected=> %#v, result=> %#v", i, test.expect, result)
}
}
}
示例2: ExampleDoc_spec
func ExampleDoc_spec() {
// Single line string is no change.
fmt.Println(heredoc.Doc(`It is single line.`))
// If first line is empty, heredoc.Doc removes first line.
fmt.Println(heredoc.Doc(`
It is first line.
It is second line.`))
// If last line is empty and more little length than indents,
// heredoc.Doc removes last line's content.
fmt.Println(heredoc.Doc(`
Next is last line.
`))
fmt.Println("Previous is last line.")
// Output:
// It is single line.
// It is first line.
// It is second line.
// Next is last line.
//
// Previous is last line.
}
示例3: ExampleDoc_lipsum
func ExampleDoc_lipsum() {
fmt.Print(heredoc.Doc(`
Lorem ipsum dolor sit amet, consectetur adipisicing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna
aliqua. Ut enim ad minim veniam, ...
`))
// Output:
// Lorem ipsum dolor sit amet, consectetur adipisicing elit,
// sed do eiusmod tempor incididunt ut labore et dolore magna
// aliqua. Ut enim ad minim veniam, ...
//
}
示例4: withFakeCommand
func withFakeCommand(t *testing.T, envValues string, block func()) {
_exec.Command = func(name string, arg ...string) *exec.Cmd {
valueFile, _ := ioutil.TempFile("", "valueFile")
valueFile.WriteString(heredoc.Doc(envValues))
valueFile.Close()
dummy, _ := ioutil.TempFile("", "dummy")
dummy.WriteString(heredoc.Docf(`
#!/bin/sh
cat %s
`, valueFile.Name()))
dummy.Close()
t.Logf("dummy: %s", dummy.Name())
os.Chmod(dummy.Name(), 0755)
return exec.Command(dummy.Name())
}
block()
}
示例5: Run
// Run launches the OpenShift master. It takes optional installers that may install additional endpoints into the server.
// All endpoints get configured CORS behavior
// Protected installers' endpoints are protected by API authentication and authorization.
// Unprotected installers' endpoints do not have any additional protection added.
func (c *MasterConfig) Run(protected []APIInstaller, unprotected []APIInstaller) {
var extra []string
safe := genericapiserver.NewHandlerContainer(http.NewServeMux(), kapi.Codecs)
open := genericapiserver.NewHandlerContainer(http.NewServeMux(), kapi.Codecs)
// enforce authentication on protected endpoints
protected = append(protected, APIInstallFunc(c.InstallProtectedAPI))
for _, i := range protected {
msgs, err := i.InstallAPI(safe)
if err != nil {
glog.Fatalf("error installing api %v", err)
}
extra = append(extra, msgs...)
}
handler := c.versionSkewFilter(safe)
handler = c.authorizationFilter(handler)
handler = c.impersonationFilter(handler)
// audit handler must comes before the impersonationFilter to read the original user
handler = c.auditHandler(handler)
handler = authenticationHandlerFilter(handler, c.Authenticator, c.getRequestContextMapper())
handler = namespacingFilter(handler, c.getRequestContextMapper())
handler = cacheControlFilter(handler, "no-store") // protected endpoints should not be cached
// unprotected resources
unprotected = append(unprotected, APIInstallFunc(c.InstallUnprotectedAPI))
for _, i := range unprotected {
msgs, err := i.InstallAPI(open)
if err != nil {
glog.Fatalf("error installing api %v", err)
}
extra = append(extra, msgs...)
}
var kubeAPILevels []string
if c.Options.KubernetesMasterConfig != nil {
kubeAPILevels = configapi.GetEnabledAPIVersionsForGroup(*c.Options.KubernetesMasterConfig, kapi.GroupName)
}
handler = indexAPIPaths(c.Options.APILevels, kubeAPILevels, handler)
open.Handle("/", handler)
// install swagger
swaggerConfig := swagger.Config{
WebServicesUrl: c.Options.MasterPublicURL,
WebServices: append(safe.RegisteredWebServices(), open.RegisteredWebServices()...),
ApiPath: swaggerAPIPrefix,
PostBuildHandler: customizeSwaggerDefinition,
}
// log nothing from swagger
swagger.LogInfo = func(format string, v ...interface{}) {}
swagger.RegisterSwaggerService(swaggerConfig, open)
extra = append(extra, fmt.Sprintf("Started Swagger Schema API at %%s%s", swaggerAPIPrefix))
openAPIConfig := openapi.Config{
SwaggerConfig: &swaggerConfig,
IgnorePrefixes: []string{"/swaggerapi"},
Info: &spec.Info{
InfoProps: spec.InfoProps{
Title: "OpenShift API (with Kubernetes)",
Version: version.Get().String(),
License: &spec.License{
Name: "Apache 2.0 (ASL2.0)",
URL: "http://www.apache.org/licenses/LICENSE-2.0",
},
Description: heredoc.Doc(`
OpenShift provides builds, application lifecycle, image content management,
and administrative policy on top of Kubernetes. The API allows consistent
management of those objects.
All API operations are authenticated via an Authorization bearer token that
is provided for service accounts as a generated secret (in JWT form) or via
the native OAuth endpoint located at /oauth/authorize. Core infrastructure
components may use client certificates that require no authentication.
All API operations return a 'resourceVersion' string that represents the
version of the object in the underlying storage. The standard LIST operation
performs a snapshot read of the underlying objects, returning a resourceVersion
representing a consistent version of the listed objects. The WATCH operation
allows all updates to a set of objects after the provided resourceVersion to
be observed by a client. By listing and beginning a watch from the returned
resourceVersion, clients may observe a consistent view of the state of one
or more objects. Note that WATCH always returns the update after the provided
resourceVersion. Watch may be extended a limited time in the past - using
etcd 2 the watch window is 1000 events (which on a large cluster may only
be a few tens of seconds) so clients must explicitly handle the "watch
to old error" by re-listing.
Objects are divided into two rough categories - those that have a lifecycle
and must reflect the state of the cluster, and those that have no state.
Objects with lifecycle typically have three main sections:
* 'metadata' common to all objects
* a 'spec' that represents the desired state
* a 'status' that represents how much of the desired state is reflected on
//.........這裏部分代碼省略.........
示例6: transformError
func transformError(err error, baseName, commandName, commandPath string, groups errorGroups) {
switch t := err.(type) {
case newcmd.ErrRequiresExplicitAccess:
if t.Input.Token != nil && t.Input.Token.ServiceAccount {
groups.Add(
"explicit-access-installer",
heredoc.Doc(`
WARNING: This will allow the pod to create and manage resources within your namespace -
ensure you trust the image with those permissions before you continue.
You can see more information about the image by adding the --dry-run flag.
If you trust the provided image, include the flag --grant-install-rights.`,
),
fmt.Errorf("installing %q requires an 'installer' service account with project editor access", t.Match.Value),
)
} else {
groups.Add(
"explicit-access-you",
heredoc.Doc(`
WARNING: This will allow the pod to act as you across the entire cluster - ensure you
trust the image with those permissions before you continue.
You can see more information about the image by adding the --dry-run flag.
If you trust the provided image, include the flag --grant-install-rights.`,
),
fmt.Errorf("installing %q requires that you grant the image access to run with your credentials", t.Match.Value),
)
}
return
case newapp.ErrNoMatch:
groups.Add(
"no-matches",
heredoc.Docf(`
The '%[1]s' command will match arguments to the following types:
1. Images tagged into image streams in the current project or the 'openshift' project
- if you don't specify a tag, we'll add ':latest'
2. Images in the Docker Hub, on remote registries, or on the local Docker engine
3. Templates in the current project or the 'openshift' project
4. Git repository URLs or local paths that point to Git repositories
--allow-missing-images can be used to point to an image that does not exist yet.
See '%[1]s -h' for examples.`, commandPath,
),
t,
t.Errs...,
)
return
case newapp.ErrMultipleMatches:
buf := &bytes.Buffer{}
for i, match := range t.Matches {
// If we have more than 5 matches, stop output and recommend searching
// after the fifth
if i >= 5 {
groups.Add(
"multiple-matches",
heredoc.Docf(`
The argument %[1]q could apply to the following Docker images, OpenShift image streams, or templates:
%[2]sTo view a full list of matches, use '%[3]s %[4]s -S %[1]s'`, t.Value, buf.String(), baseName, commandName,
),
t,
t.Errs...,
)
return
}
fmt.Fprintf(buf, "* %s\n", match.Description)
fmt.Fprintf(buf, " Use %[1]s to specify this image or template\n\n", match.Argument)
}
groups.Add(
"multiple-matches",
heredoc.Docf(`
The argument %[1]q could apply to the following Docker images, OpenShift image streams, or templates:
%[2]s`, t.Value, buf.String(),
),
t,
t.Errs...,
)
return
case newapp.ErrPartialMatch:
buf := &bytes.Buffer{}
fmt.Fprintf(buf, "* %s\n", t.Match.Description)
fmt.Fprintf(buf, " Use %[1]s to specify this image or template\n\n", t.Match.Argument)
groups.Add(
"partial-match",
heredoc.Docf(`
The argument %[1]q only partially matched the following Docker image, OpenShift image stream, or template:
%[2]s`, t.Value, buf.String(),
),
t,
t.Errs...,
)
//.........這裏部分代碼省略.........
示例7:
"github.com/openshift/origin/pkg/cmd/util/clientcmd"
)
type concept struct {
Name string
Abbreviation string
Description string
}
var concepts = []concept{
{
"Containers",
"",
heredoc.Doc(`
A definition of how to run one or more processes inside of a portable Linux
environment. Containers are started from an Image and are usually isolated
from other containers on the same machine.
`),
},
{
"Image",
"",
heredoc.Doc(`
A layered Linux filesystem that contains application code, dependencies,
and any supporting operating system libraries. An image is identified by
a name that can be local to the current cluster or point to a remote Docker
registry (a storage server for images).
`),
}, {
"Pods",
"pod",
示例8: heredoc
func (s normalizer) heredoc() normalizer {
s.string = heredoc.Doc(s.string)
return s
}
示例9: TestTLSWithCertificateNotMatchingHostname
func TestTLSWithCertificateNotMatchingHostname(t *testing.T) {
// generated by 'go run src/crypto/tls/generate_cert.go --rsa-bits 1024 --host invalidhost.com,8.8.8.8 --ca --start-date "Jan 1 00:00:00 1970" --duration=1000000h'
invalidHostCert := heredoc.Doc(`
-----BEGIN CERTIFICATE-----
MIICBjCCAW+gAwIBAgIRALOIWXyeLzunaiVkP2itHAEwDQYJKoZIhvcNAQELBQAw
EjEQMA4GA1UEChMHQWNtZSBDbzAgFw03MDAxMDEwMDAwMDBaGA8yMDg0MDEyOTE2
MDAwMFowEjEQMA4GA1UEChMHQWNtZSBDbzCBnzANBgkqhkiG9w0BAQEFAAOBjQAw
gYkCgYEAuKDlC4aMBbHaXgS+MFud5h3zeE4boSqKgFI6HceySF/a+qg0v+ID6EwQ
DpJ2W5AdJGEBfixo+tym6q3oKWHJUX0hInkJ6dXIdUbVOeO5dIsGG0fZmRD7DDDx
snkXrDB/E0JglHNckRbIh/jvznbDfbddIcdgZ7JVIfnNpigtHZECAwEAAaNaMFgw
DgYDVR0PAQH/BAQDAgKkMBMGA1UdJQQMMAoGCCsGAQUFBwMBMA8GA1UdEwEB/wQF
MAMBAf8wIAYDVR0RBBkwF4IPaW52YWxpZGhvc3QuY29thwQICAgIMA0GCSqGSIb3
DQEBCwUAA4GBAAkPU044aFkBl4f/muwSh/oPGinnA4fp8ei0KMnLk+0/CjNb3Waa
GtuRVIudRTK2M/RzdpUrwfWlVmkezV4BR1K/aOH9a29zqDTkEjnkIbWwe+piAs+w
VxIxrTqM8rqq8qxeWS54AyF/OaLJgXzDpCFnCb7kY3iyHv6lcmCjluLW
-----END CERTIFICATE-----`)
invalidHostKey := heredoc.Doc(`
-----BEGIN RSA PRIVATE KEY-----
MIICXQIBAAKBgQC4oOULhowFsdpeBL4wW53mHfN4ThuhKoqAUjodx7JIX9r6qDS/
4gPoTBAOknZbkB0kYQF+LGj63KbqregpYclRfSEieQnp1ch1RtU547l0iwYbR9mZ
EPsMMPGyeResMH8TQmCUc1yRFsiH+O/OdsN9t10hx2BnslUh+c2mKC0dkQIDAQAB
AoGAZ0ZAuNC7NFhHEL5QcJZe3aC1Vv9B/0XfkWXtckkJFejggcNjNk5D50Xc2Xnd
0NvtITNN9Xj8BA83IyDCM5uqUwDbOLIc6qYgAGWzxZZSDAQg1iOAAZoXmMTNS6Zf
hQhNUIwB68ELGvbcq7cxQL7L9n4GfISz7PKOOUKTZp0Q8G0CQQD07K7NES340c3I
QVkCW5/ygNK0GuQ8nTcG5yC8R5SDS47N8YzPp17Pajah8+wawYiemY1fUmD7P/bq
Cjl2RtIHAkEAwPo1GzJubN7PSYgPir3TxUGtMJoyc3jfdjblXyGJHwTu2YxeRjd2
YUPVRpu9JvNjZc+GONvTbTZeNWCvy0JNpwJBAKEsi49JCd6eefOZBTDnCKd1nLKG
q8Ezl/2D5WfhFtsbwrrFhOs1cc++Tnte3/VvfC8aTwz2UfmkyyCSX+P0kMsCQCIL
glb7/LNEU7mbQXKurq+8OHu8mG36wyGt6aVw2yoXyrOiqfclTcM3HmdIjoRSqBSM
Ghfp4FECKHiuSBVJ6z0CQQDF37CRpdQRDPnAedhyApLcIxSbYo1oUm7FxBLyVb7V
HQjFvsOylsSCABXz0FyC7zXQxkEo6CiSahVI/PHz6Zta
-----END RSA PRIVATE KEY-----`)
server, err := newTLSServer(invalidHostCert, invalidHostKey)
if err != nil {
t.Errorf(err.Error())
}
server.StartTLS()
defer server.Close()
testCases := map[string]struct {
serverURL string
skipTLSVerify bool
expectedErrMsg *regexp.Regexp
}{
"succeed skipping tls": {
serverURL: server.URL,
skipTLSVerify: true,
},
"certificate hostname doesn't match": {
serverURL: server.URL,
expectedErrMsg: regexp.MustCompile(`The server is using a certificate that does not match its hostname(.*)is valid for 8\.8\.8\.8`),
},
}
for name, test := range testCases {
t.Logf("evaluating test: %s", name)
options := &LoginOptions{
Server: test.serverURL,
InsecureTLS: test.skipTLSVerify,
StartingKubeConfig: &kclientcmdapi.Config{},
}
if _, err = options.getClientConfig(); err != nil {
if !test.expectedErrMsg.MatchString(err.Error()) {
t.Errorf("%s: expected error %q but got %q", name, test.expectedErrMsg, err)
}
if test.expectedErrMsg == nil {
t.Errorf("%s: unexpected error: %v", name, err)
}
} else {
if test.expectedErrMsg != nil {
t.Errorf("%s: expected error but got nothing", name)
}
}
}
}
示例10: TestTLSWithExpiredCertificate
func TestTLSWithExpiredCertificate(t *testing.T) {
// generated by 'go run src/crypto/tls/generate_cert.go --rsa-bits 1024 --host 127.0.0.1,::1,example.com --ca --start-date "Jan 1 00:00:00 1970" --duration=1h'
expiredCert := heredoc.Doc(`
-----BEGIN CERTIFICATE-----
MIICEjCCAXugAwIBAgIRALf82bYpro/jQS8fP74dG5EwDQYJKoZIhvcNAQELBQAw
EjEQMA4GA1UEChMHQWNtZSBDbzAeFw03MDAxMDEwMDAwMDBaFw03MDAxMDEwMTAw
MDBaMBIxEDAOBgNVBAoTB0FjbWUgQ28wgZ8wDQYJKoZIhvcNAQEBBQADgY0AMIGJ
AoGBAONNgDXBk2Q1i/aJjTwt03KpQ3nQblMS3IX/H9JWw6ta6UublKBOaD/2o5Xt
FM+Q7XDEnzYw88CK5KHdyejkJo5IBpUjQYJZFzUJ1BC8Lw7yy6dXWYBJboRR1S+1
JhkMJOtpPecv+4cTaynplYj0WMBjcQthg2RM7tdpyUYpsp2rAgMBAAGjaDBm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z2mc65KsfOPe2IqNcOrDlx4mCWVXxtRdN+933mcPcDRpnMFSlo
oH/NO9Ha6M8L2SjjjyohAkBJHU61+OWz/TAy1nxsMbFsISLn/JrdEZIf2uFORlDN
Z3/XIQ+yeg4Jk1VbTMZ0/fHf9xMFR8acC/7n7jxnzQau
-----END RSA PRIVATE KEY-----`)
server, err := newTLSServer(expiredCert, expiredKey)
if err != nil {
t.Errorf(err.Error())
}
server.StartTLS()
defer server.Close()
testCases := map[string]struct {
serverURL string
skipTLSVerify bool
expectedErrMsg *regexp.Regexp
}{
"succeed skipping tls": {
serverURL: server.URL,
skipTLSVerify: true,
},
"certificate expired": {
serverURL: server.URL,
expectedErrMsg: regexp.MustCompile(`The server is using an invalid certificate(.*)has expired`),
},
}
for name, test := range testCases {
t.Logf("evaluating test: %s", name)
options := &LoginOptions{
Server: test.serverURL,
InsecureTLS: test.skipTLSVerify,
StartingKubeConfig: &kclientcmdapi.Config{},
}
if _, err = options.getClientConfig(); err != nil {
if !test.expectedErrMsg.MatchString(err.Error()) {
t.Errorf("%s: expected error %q but got %q", name, test.expectedErrMsg, err)
}
if test.expectedErrMsg == nil {
t.Errorf("%s: unexpected error: %v", name, err)
}
} else {
if test.expectedErrMsg != nil {
t.Errorf("%s: expected error but got nothing", name)
}
}
}
}
示例11: D
// Shortcut heredoc.Doc
func D(raw string) string {
return heredoc.Doc(raw)
}