github.com/solo-io/cue@v0.4.7/pkg/tool/http/gen.go (about)

     1  // Copyright 2019 CUE Authors
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License");
     4  // you may not use this file except in compliance with the License.
     5  // You may obtain a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS,
    11  // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    12  // See the License for the specific language governing permissions and
    13  // limitations under the License.
    14  
    15  //go:build ignore
    16  // +build ignore
    17  
    18  package main
    19  
    20  // TODO: remove when we have a cuedoc server. Until then,
    21  // piggyback on pkg.go.dev.
    22  
    23  import (
    24  	"bytes"
    25  	"fmt"
    26  	"io/ioutil"
    27  	"os"
    28  )
    29  
    30  const msg = `// Code generated by cue get go. DO NOT EDIT.
    31  
    32  // Package http provides tasks related to the HTTP protocol.
    33  //
    34  // These are the supported tasks:
    35  //     %s
    36  package http
    37  `
    38  
    39  func main() {
    40  	f, _ := os.Create("doc.go")
    41  	defer f.Close()
    42  	b, _ := ioutil.ReadFile("http.cue")
    43  	i := bytes.Index(b, []byte("package http"))
    44  	b = b[i+len("package http")+1:]
    45  	b = bytes.ReplaceAll(b, []byte("\n"), []byte("\n//     "))
    46  	fmt.Fprintf(f, msg, string(b))
    47  }