element_type stringclasses 2
values | project_name stringclasses 2
values | uuid stringlengths 36 36 | name stringlengths 3 29 | imports stringlengths 0 312 | structs stringclasses 7
values | interfaces stringclasses 1
value | file_location stringlengths 58 108 | code stringlengths 41 7.22k | global_vars stringclasses 3
values | package stringclasses 11
values | tags stringclasses 1
value |
|---|---|---|---|---|---|---|---|---|---|---|---|
file | flightctl/test | aff77152-419a-4026-b474-ad2c9c7ed20a | app.go | import (
"fmt"
"net/http"
) | github.com/flightctl/test//tmp/repos/example/appengine-hello/app.go | // Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package hello is a simple App Engine application that replies to requests
// on /hello with a welcoming message.
package hello
import (
"fmt"
"net/http"
)... | package hello | ||||
function | flightctl/test | 33b13e28-b164-4022-ae4e-64e051666113 | init | ['"net/http"'] | github.com/flightctl/test//tmp/repos/example/appengine-hello/app.go | func init() {
// Handle all requests with path /hello with the helloHandler function.
http.HandleFunc("/hello", helloHandler)
} | hello | ||||
function | flightctl/test | 3835848d-adad-42d1-9a8c-92598834aa78 | helloHandler | ['"fmt"', '"net/http"'] | github.com/flightctl/test//tmp/repos/example/appengine-hello/app.go | func helloHandler(w http.ResponseWriter, r *http.Request) {
fmt.Fprintln(w, "Hello from the Go app")
} | hello | ||||
file | flightctl/test | 220df757-95a9-43f9-a971-2787d6919986 | main.go | import (
"fmt"
"go/ast"
"go/importer"
"go/parser"
"go/token"
"go/types"
"log"
) | github.com/flightctl/test//tmp/repos/example/gotypes/defsuses/main.go | package main
import (
"fmt"
"go/ast"
"go/importer"
"go/parser"
"go/token"
"go/types"
"log"
)
const hello = `package main
import "fmt"
func main() {
fmt.Println("Hello, world")
}
`
// !+
func PrintDefsUses(fset *token.FileSet, files ...*ast.File) error {
conf := types.Config{Importer: importer.Defau... | package main | ||||
function | flightctl/test | 065f41b3-1709-4f85-91ab-ff12eb6eb053 | PrintDefsUses | ['"fmt"', '"go/ast"', '"go/importer"', '"go/token"', '"go/types"'] | github.com/flightctl/test//tmp/repos/example/gotypes/defsuses/main.go | func PrintDefsUses(fset *token.FileSet, files ...*ast.File) error {
conf := types.Config{Importer: importer.Default()}
info := &types.Info{
Defs: make(map[*ast.Ident]types.Object),
Uses: make(map[*ast.Ident]types.Object),
}
_, err := conf.Check("hello", fset, files, info)
if err != nil {
return err // type e... | main | ||||
function | flightctl/test | 827980b3-2da1-447e-996e-cde075912651 | main | ['"go/parser"', '"go/token"', '"log"'] | github.com/flightctl/test//tmp/repos/example/gotypes/defsuses/main.go | func main() {
// Parse one file.
fset := token.NewFileSet()
f, err := parser.ParseFile(fset, "hello.go", hello, 0)
if err != nil {
log.Fatal(err) // parse error
}
if err := PrintDefsUses(fset, f); err != nil {
log.Fatal(err) // type error
}
} | main | ||||
file | flightctl/test | 24aa19a1-0158-4984-b8c0-28ddf2d4bd87 | main.go | import (
"fmt"
"go/ast"
"log"
"os"
"golang.org/x/tools/go/ast/astutil"
"golang.org/x/tools/go/packages"
"golang.org/x/tools/go/types/typeutil"
) | github.com/flightctl/test//tmp/repos/example/gotypes/doc/main.go | // The doc command prints the doc comment of a package-level object.
package main
import (
"fmt"
"go/ast"
"log"
"os"
"golang.org/x/tools/go/ast/astutil"
"golang.org/x/tools/go/packages"
"golang.org/x/tools/go/types/typeutil"
)
func main() {
if len(os.Args) != 3 {
log.Fatal("Usage: doc <package> <object>")
... | package main | ||||
function | flightctl/test | 06321b20-6092-463b-bd39-cc7cf1c49227 | main | ['"fmt"', '"go/ast"', '"log"', '"os"', '"golang.org/x/tools/go/ast/astutil"', '"golang.org/x/tools/go/packages"', '"golang.org/x/tools/go/types/typeutil"'] | github.com/flightctl/test//tmp/repos/example/gotypes/doc/main.go | func main() {
if len(os.Args) != 3 {
log.Fatal("Usage: doc <package> <object>")
}
//!+part1
pkgpath, name := os.Args[1], os.Args[2]
// Load complete type information for the specified packages,
// along with type-annotated syntax.
// Types for dependencies are loaded from export data.
conf := &packages.Confi... | main | ||||
file | flightctl/test | 055a9263-7da9-4606-9c90-8a5dc5f19e0c | gen.go | github.com/flightctl/test//tmp/repos/example/gotypes/gen.go | //go:generate bash -c "go run ../internal/cmd/weave/weave.go ./go-types.md > README.md"
package gotypes
| package gotypes | |||||
file | flightctl/test | 082bab20-4a7e-450e-b7b2-a00b9de05d1a | hello.go | import "fmt" | github.com/flightctl/test//tmp/repos/example/gotypes/hello/hello.go | // !+
package main
import "fmt"
func main() {
fmt.Println("Hello, 世界")
}
//!-
| package main | ||||
function | flightctl/test | 54bbfd5d-7ee3-4f52-81e6-29d950e11ed9 | main | github.com/flightctl/test//tmp/repos/example/gotypes/hello/hello.go | func main() {
fmt.Println("Hello, 世界")
} | main | |||||
file | flightctl/test | 85f31eb9-eb56-48ee-a86f-caf0185e944d | main.go | import (
"flag"
"fmt"
"go/ast"
"go/token"
"go/types"
"log"
"os"
"golang.org/x/tools/go/packages"
) | github.com/flightctl/test//tmp/repos/example/gotypes/hugeparam/main.go | // The hugeparam command identifies by-value parameters that are larger than n bytes.
//
// Example:
//
// $ ./hugeparams encoding/xml
package main
import (
"flag"
"fmt"
"go/ast"
"go/token"
"go/types"
"log"
"os"
"golang.org/x/tools/go/packages"
)
// !+
var bytesFlag = flag.Int("bytes", 48, "maximum parameter... | package main | ||||
function | flightctl/test | 3a9d387b-412a-4d54-8162-68372c00992f | PrintHugeParams | ['"fmt"', '"go/ast"', '"go/token"', '"go/types"'] | github.com/flightctl/test//tmp/repos/example/gotypes/hugeparam/main.go | func PrintHugeParams(fset *token.FileSet, info *types.Info, sizes types.Sizes, files []*ast.File) {
checkTuple := func(descr string, tuple *types.Tuple) {
for i := 0; i < tuple.Len(); i++ {
v := tuple.At(i)
if sz := sizes.Sizeof(v.Type()); sz > int64(*bytesFlag) {
fmt.Printf("%s: %q %s: %s = %d bytes\n",
... | {'bytesFlag': 'flag.Int("bytes", 48, "maximum parameter size in bytes")'} | main | |||
function | flightctl/test | d3f7be96-c7e7-4ae8-be2b-5f649faf4624 | main | ['"flag"', '"log"', '"os"', '"golang.org/x/tools/go/packages"'] | github.com/flightctl/test//tmp/repos/example/gotypes/hugeparam/main.go | func main() {
flag.Parse()
// Load complete type information for the specified packages,
// along with type-annotated syntax and the "sizeof" function.
// Types for dependencies are loaded from export data.
conf := &packages.Config{Mode: packages.LoadSyntax}
pkgs, err := packages.Load(conf, flag.Args()...)
if e... | main | ||||
file | flightctl/test | cfac8e1b-dcc6-459b-90ed-11e86aee9462 | main.go | import (
"fmt"
"go/ast"
"go/importer"
"go/parser"
"go/token"
"go/types"
"log"
) | github.com/flightctl/test//tmp/repos/example/gotypes/implements/main.go | package main
import (
"fmt"
"go/ast"
"go/importer"
"go/parser"
"go/token"
"go/types"
"log"
)
// !+input
const input = `package main
type A struct{}
func (*A) f()
type B int
func (B) f()
func (*B) g()
type I interface { f() }
type J interface { g() }
`
//!-input
func main() {
// Parse one file.
fset := t... | package main | ||||
function | flightctl/test | ce6138ec-bd6f-420b-b2b8-9efcc3a70b53 | main | ['"fmt"', '"go/ast"', '"go/importer"', '"go/parser"', '"go/token"', '"go/types"', '"log"'] | github.com/flightctl/test//tmp/repos/example/gotypes/implements/main.go | func main() {
// Parse one file.
fset := token.NewFileSet()
f, err := parser.ParseFile(fset, "input.go", input, 0)
if err != nil {
log.Fatal(err) // parse error
}
conf := types.Config{Importer: importer.Default()}
pkg, err := conf.Check("hello", fset, []*ast.File{f}, nil)
if err != nil {
log.Fatal(err) // t... | main | ||||
file | flightctl/test | 91bc238e-8588-453b-888e-3e91c12f623d | lookup.go | import (
"fmt"
"go/ast"
"go/importer"
"go/parser"
"go/token"
"go/types"
"log"
"strings"
) | github.com/flightctl/test//tmp/repos/example/gotypes/lookup/lookup.go | package main
import (
"fmt"
"go/ast"
"go/importer"
"go/parser"
"go/token"
"go/types"
"log"
"strings"
)
// !+input
const hello = `
package main
import "fmt"
// append
func main() {
// fmt
fmt.Println("Hello, world")
// main
main, x := 1, 2
// main
print(main, x... | package main | ||||
function | flightctl/test | 90581d41-af99-4624-a0a4-dd15952342cf | main | ['"fmt"', '"go/ast"', '"go/importer"', '"go/parser"', '"go/token"', '"go/types"', '"log"', '"strings"'] | github.com/flightctl/test//tmp/repos/example/gotypes/lookup/lookup.go | func main() {
fset := token.NewFileSet()
f, err := parser.ParseFile(fset, "hello.go", hello, parser.ParseComments)
if err != nil {
log.Fatal(err) // parse error
}
conf := types.Config{Importer: importer.Default()}
pkg, err := conf.Check("cmd/hello", fset, []*ast.File{f}, nil)
if err != nil {
log.Fatal(err) ... | main | ||||
file | flightctl/test | 6f8b713f-27ed-4b8e-bc5f-395127fb5701 | main.go | import (
"fmt"
"go/ast"
"go/importer"
"go/parser"
"go/token"
"go/types"
"log"
) | github.com/flightctl/test//tmp/repos/example/gotypes/nilfunc/main.go | package main
import (
"fmt"
"go/ast"
"go/importer"
"go/parser"
"go/token"
"go/types"
"log"
)
// !+input
const input = `package main
import "bytes"
func main() {
var buf bytes.Buffer
if buf.Bytes == nil && bytes.Repeat != nil && main == nil {
// ...
}
}
`
//!-input
var fset = token.NewFileSet()
func m... | package main | ||||
function | flightctl/test | c33f15bb-af0f-4269-ad72-8fd3d0ea02cd | main | ['"go/ast"', '"go/importer"', '"go/parser"', '"go/types"', '"log"'] | github.com/flightctl/test//tmp/repos/example/gotypes/nilfunc/main.go | func main() {
f, err := parser.ParseFile(fset, "input.go", input, 0)
if err != nil {
log.Fatal(err) // parse error
}
conf := types.Config{Importer: importer.Default()}
info := &types.Info{
Defs: make(map[*ast.Ident]types.Object),
Uses: make(map[*ast.Ident]types.Object),
Types: make(map[ast.Expr]types.Typ... | {'fset': 'token.NewFileSet()'} | main | |||
function | flightctl/test | e1f188e1-0299-49da-bece-cdad3bf8b321 | CheckNilFuncComparison | ['"fmt"', '"go/ast"', '"go/token"', '"go/types"'] | github.com/flightctl/test//tmp/repos/example/gotypes/nilfunc/main.go | func CheckNilFuncComparison(info *types.Info, n ast.Node) {
e, ok := n.(*ast.BinaryExpr)
if !ok {
return // not a binary operation
}
if e.Op != token.EQL && e.Op != token.NEQ {
return // not a comparison
}
// If this is a comparison against nil, find the other operand.
var other ast.Expr
if info.Types[e.X]... | {'fset': 'token.NewFileSet()'} | main | |||
file | flightctl/test | 710f06e9-ca1a-44f4-b262-92893ef9895f | main.go | import (
"fmt"
"go/ast"
"go/importer"
"go/parser"
"go/token"
"go/types"
"log"
) | github.com/flightctl/test//tmp/repos/example/gotypes/pkginfo/main.go | // !+
package main
import (
"fmt"
"go/ast"
"go/importer"
"go/parser"
"go/token"
"go/types"
"log"
)
const hello = `package main
import "fmt"
func main() {
fmt.Println("Hello, world")
}`
func main() {
fset := token.NewFileSet()
// Parse the input string, []byte, or io.Reader,
// recording position... | package main | ||||
function | flightctl/test | 29fa69b0-0073-4056-816b-8ed514cd407c | main | ['"fmt"', '"go/ast"', '"go/importer"', '"go/parser"', '"go/token"', '"go/types"', '"log"'] | github.com/flightctl/test//tmp/repos/example/gotypes/pkginfo/main.go | func main() {
fset := token.NewFileSet()
// Parse the input string, []byte, or io.Reader,
// recording position information in fset.
// ParseFile returns an *ast.File, a syntax tree.
f, err := parser.ParseFile(fset, "hello.go", hello, 0)
if err != nil {
log.Fatal(err) // parse error
}
// A Config controls v... | main | ||||
file | flightctl/test | 828a67e4-c87b-44cc-ae6a-0f55fdcc7700 | main.go | import (
"fmt"
"go/types"
"log"
"os"
"strings"
"unicode"
"unicode/utf8"
"golang.org/x/tools/go/packages"
) | github.com/flightctl/test//tmp/repos/example/gotypes/skeleton/main.go | // The skeleton command prints the boilerplate for a concrete type
// that implements the specified interface type.
//
// Example:
//
// $ ./skeleton io ReadWriteCloser buffer
// // *buffer implements io.ReadWriteCloser.
// type buffer struct{ /* ... */ }
// func (b *buffer) Close() error { panic("unimplemented") }
// ... | package main | ||||
function | flightctl/test | 3507dc64-8155-4a9b-a1a6-b5479226b5d4 | PrintSkeleton | ['"fmt"', '"go/types"', '"strings"', '"unicode/utf8"'] | github.com/flightctl/test//tmp/repos/example/gotypes/skeleton/main.go | func PrintSkeleton(pkg *types.Package, ifacename, concname string) error {
obj := pkg.Scope().Lookup(ifacename)
if obj == nil {
return fmt.Errorf("%s.%s not found", pkg.Path(), ifacename)
}
if _, ok := obj.(*types.TypeName); !ok {
return fmt.Errorf("%v is not a named type", obj)
}
iface, ok := obj.Type().Unde... | main | ||||
function | flightctl/test | e250faf2-d0e9-4d3c-9ab4-03317b4c9f11 | isValidIdentifier | ['"unicode"'] | github.com/flightctl/test//tmp/repos/example/gotypes/skeleton/main.go | func isValidIdentifier(id string) bool {
for i, r := range id {
if !unicode.IsLetter(r) &&
!(i > 0 && unicode.IsDigit(r)) {
return false
}
}
return id != ""
} | main | ||||
function | flightctl/test | 432b7863-53aa-404b-a8b3-29a09b008e9e | main | ['"log"', '"os"', '"golang.org/x/tools/go/packages"'] | github.com/flightctl/test//tmp/repos/example/gotypes/skeleton/main.go | func main() {
if len(os.Args) != 4 {
log.Fatal(usage)
}
pkgpath, ifacename, concname := os.Args[1], os.Args[2], os.Args[3]
// Load only exported type information for the specified package.
conf := &packages.Config{Mode: packages.NeedTypes}
pkgs, err := packages.Load(conf, pkgpath)
if err != nil {
log.Fatal(... | main | ||||
file | flightctl/test | 72d9a912-9dfb-4845-b902-1b56dba7416d | main.go | import (
"bytes"
"fmt"
"go/ast"
"go/format"
"go/importer"
"go/parser"
"go/token"
"go/types"
"log"
) | github.com/flightctl/test//tmp/repos/example/gotypes/typeandvalue/main.go | package main
import (
"bytes"
"fmt"
"go/ast"
"go/format"
"go/importer"
"go/parser"
"go/token"
"go/types"
"log"
)
// !+input
const input = `
package main
var m = make(map[string]int)
func main() {
v, ok := m["hello, " + "world"]
print(rune(v), ok)
}
`
//!-input
var fset = token.NewFileSet()
func main()... | package main | ||||
function | flightctl/test | 3ce79319-2531-43ce-bee1-ceab00a4e22f | main | ['"fmt"', '"go/ast"', '"go/importer"', '"go/parser"', '"go/types"', '"log"'] | github.com/flightctl/test//tmp/repos/example/gotypes/typeandvalue/main.go | func main() {
f, err := parser.ParseFile(fset, "hello.go", input, 0)
if err != nil {
log.Fatal(err) // parse error
}
conf := types.Config{Importer: importer.Default()}
info := &types.Info{Types: make(map[ast.Expr]types.TypeAndValue)}
if _, err := conf.Check("cmd/hello", fset, []*ast.File{f}, info); err != nil ... | {'fset': 'token.NewFileSet()'} | main | |||
function | flightctl/test | 9beb2665-4476-4b62-8d6e-63ad65916165 | nodeString | ['"bytes"', '"go/ast"', '"go/format"'] | github.com/flightctl/test//tmp/repos/example/gotypes/typeandvalue/main.go | func nodeString(n ast.Node) string {
var buf bytes.Buffer
format.Node(&buf, fset, n)
return buf.String()
} | {'fset': 'token.NewFileSet()'} | main | |||
function | flightctl/test | b860b0a5-cb1c-443a-a905-17aa68c8579f | mode | ['"go/types"'] | github.com/flightctl/test//tmp/repos/example/gotypes/typeandvalue/main.go | func mode(tv types.TypeAndValue) string {
s := ""
if tv.IsVoid() {
s += ",void"
}
if tv.IsType() {
s += ",type"
}
if tv.IsBuiltin() {
s += ",builtin"
}
if tv.IsValue() {
s += ",value"
}
if tv.IsNil() {
s += ",nil"
}
if tv.Addressable() {
s += ",addressable"
}
if tv.Assignable() {
s += ",assi... | main | ||||
file | flightctl/test | 9323729c-68b1-4821-8164-121cd011a4a1 | hello.go | import (
"flag"
"fmt"
"log"
"os"
"golang.org/x/example/hello/reverse"
) | github.com/flightctl/test//tmp/repos/example/hello/hello.go | // Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Hello is a hello, world program, demonstrating
// how to write a simple command-line program.
//
// Usage:
//
// hello [options] [name]
//
// The options are... | package main | ||||
function | flightctl/test | cf5db83b-96d5-49c8-834d-10f7517bede8 | usage | ['"flag"', '"fmt"', '"os"'] | github.com/flightctl/test//tmp/repos/example/hello/hello.go | func usage() {
fmt.Fprintf(os.Stderr, "usage: hello [options] [name]\n")
flag.PrintDefaults()
os.Exit(2)
} | main | ||||
function | flightctl/test | 3842a86b-6609-49bf-8d70-1dea39e3839a | main | ['"flag"', '"fmt"', '"log"', '"golang.org/x/example/hello/reverse"'] | github.com/flightctl/test//tmp/repos/example/hello/hello.go | func main() {
// Configure logging for a command-line program.
log.SetFlags(0)
log.SetPrefix("hello: ")
// Parse flags.
flag.Usage = usage
flag.Parse()
// Parse and validate arguments.
name := "world"
args := flag.Args()
if len(args) >= 2 {
usage()
}
if len(args) >= 1 {
name = args[0]
}
if name == "... | main | ||||
file | flightctl/test | 289c8def-db4f-4c0c-a0cb-2521935ffd35 | example_test.go | import (
"fmt"
"golang.org/x/example/hello/reverse"
) | github.com/flightctl/test//tmp/repos/example/hello/reverse/example_test.go | // Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package reverse_test
import (
"fmt"
"golang.org/x/example/hello/reverse"
)
func ExampleString() {
fmt.Println(reverse.String("hello"))
// Output: olleh
}... | package reverse_test | ||||
function | flightctl/test | 82c375de-2c4a-44f5-b083-df78340da8b4 | ExampleString | ['"fmt"', '"golang.org/x/example/hello/reverse"'] | github.com/flightctl/test//tmp/repos/example/hello/reverse/example_test.go | func ExampleString() {
fmt.Println(reverse.String("hello"))
// Output: olleh
} | reverse_test | ||||
file | flightctl/test | cf2f6fd7-788c-4872-b0a0-fbb607b1bec8 | reverse.go | github.com/flightctl/test//tmp/repos/example/hello/reverse/reverse.go | // Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Package reverse can reverse things, particularly strings.
package reverse
// String returns its argument string reversed rune-wise left to right.
func Strin... | package reverse | |||||
function | flightctl/test | d87b0624-429e-4bab-929a-4b3193b1441d | String | github.com/flightctl/test//tmp/repos/example/hello/reverse/reverse.go | func String(s string) string {
r := []rune(s)
for i, j := 0, len(r)-1; i < len(r)/2; i, j = i+1, j-1 {
r[i], r[j] = r[j], r[i]
}
return string(r)
} | reverse | |||||
file | flightctl/test | 4a966f10-adf8-4df1-ab88-859c2bda699c | reverse_test.go | import "testing" | github.com/flightctl/test//tmp/repos/example/hello/reverse/reverse_test.go | // Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package reverse
import "testing"
func TestString(t *testing.T) {
for _, c := range []struct {
in, want string
}{
{"Hello, world", "dlrow ,olleH"},
{"H... | package reverse | ||||
function | flightctl/test | 273990a4-0d9c-4feb-ad38-2e0b66e67a78 | TestString | github.com/flightctl/test//tmp/repos/example/hello/reverse/reverse_test.go | func TestString(t *testing.T) {
for _, c := range []struct {
in, want string
}{
{"Hello, world", "dlrow ,olleH"},
{"Hello, 世界", "界世 ,olleH"},
{"", ""},
} {
got := String(c.in)
if got != c.want {
t.Errorf("String(%q) == %q, want %q", c.in, got, c.want)
}
}
} | reverse | |||||
file | flightctl/test | af137d20-eda5-4939-b569-bf228035bb1b | server.go | import (
"flag"
"fmt"
"html"
"log"
"net/http"
"os"
"runtime/debug"
"strings"
) | github.com/flightctl/test//tmp/repos/example/helloserver/server.go | // Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Hello is a simple hello, world demonstration web server.
//
// It serves version information on /version and answers
// any other request like /name by sayin... | package main | ||||
function | flightctl/test | dbbbda4d-7d41-4bd2-bd42-81678921491c | usage | ['"flag"', '"fmt"', '"os"'] | github.com/flightctl/test//tmp/repos/example/helloserver/server.go | func usage() {
fmt.Fprintf(os.Stderr, "usage: helloserver [options]\n")
flag.PrintDefaults()
os.Exit(2)
} | main | ||||
function | flightctl/test | f7d6307a-8e6b-4050-8423-daf14dd81e79 | main | ['"flag"', '"log"', '"net/http"'] | github.com/flightctl/test//tmp/repos/example/helloserver/server.go | func main() {
// Parse flags.
flag.Usage = usage
flag.Parse()
// Parse and validate arguments (none).
args := flag.Args()
if len(args) != 0 {
usage()
}
// Register handlers.
// All requests not otherwise mapped with go to greet.
// /version is mapped specifically to version.
http.HandleFunc("/", greet)
... | main | ||||
function | flightctl/test | d757539a-0fc9-4dc6-a1b3-b73e1607d313 | version | ['"fmt"', '"html"', '"net/http"', '"runtime/debug"'] | github.com/flightctl/test//tmp/repos/example/helloserver/server.go | func version(w http.ResponseWriter, r *http.Request) {
info, ok := debug.ReadBuildInfo()
if !ok {
http.Error(w, "no build information available", 500)
return
}
fmt.Fprintf(w, "<!DOCTYPE html>\n<pre>\n")
fmt.Fprintf(w, "%s\n", html.EscapeString(info.String()))
} | main | ||||
function | flightctl/test | e1533996-f738-48d0-8177-595adf7810df | greet | ['"fmt"', '"html"', '"net/http"', '"strings"'] | github.com/flightctl/test//tmp/repos/example/helloserver/server.go | func greet(w http.ResponseWriter, r *http.Request) {
name := strings.Trim(r.URL.Path, "/")
if name == "" {
name = "Gopher"
}
fmt.Fprintf(w, "<!DOCTYPE html>\n")
fmt.Fprintf(w, "%s, %s!\n", *greeting, html.EscapeString(name))
} | main | ||||
file | flightctl/test | 878ae366-fdf5-4e82-8c6b-dd79068f6c5c | weave.go | import (
"bufio"
"bytes"
"fmt"
"log"
"os"
"path/filepath"
"regexp"
"strings"
) | github.com/flightctl/test//tmp/repos/example/internal/cmd/weave/weave.go | // The weave command is a simple preprocessor for markdown files.
// It builds a table of contents and processes %include directives.
//
// Example usage:
//
// $ go run internal/cmd/weave go-types.md > README.md
//
// The weave command copies lines of the input file to standard output, with two
// exceptions:
//
// If... | package main | ||||
function | flightctl/test | 16b8ae9a-3804-4e89-933d-fb3071fedca7 | main | ['"bufio"', '"fmt"', '"log"', '"os"', '"path/filepath"', '"strings"'] | github.com/flightctl/test//tmp/repos/example/internal/cmd/weave/weave.go | func main() {
log.SetFlags(0)
log.SetPrefix("weave: ")
if len(os.Args) != 2 {
log.Fatal("usage: weave input.md\n")
}
f, err := os.Open(os.Args[1])
if err != nil {
log.Fatal(err)
}
defer f.Close()
wd, err := os.Getwd()
if err != nil {
log.Fatal(err)
}
curDir := filepath.Base(wd)
fmt.Println("<!-- A... | main | ||||
function | flightctl/test | 7ffeb10c-4c7e-42be-ad55-f6ead17808db | include | ['"bufio"', '"bytes"', '"fmt"', '"os"', '"regexp"'] | github.com/flightctl/test//tmp/repos/example/internal/cmd/weave/weave.go | func include(file, tag string) (string, error) {
f, err := os.Open(file)
if err != nil {
return "", err
}
defer f.Close()
startre, err := regexp.Compile("!\\+" + tag + "$")
if err != nil {
return "", err
}
endre, err := regexp.Compile("!\\-" + tag + "$")
if err != nil {
return "", err
}
var text byte... | main | ||||
function | flightctl/test | e406026c-a950-4b9e-b20c-9df4631cbab2 | isBlank | ['"strings"'] | github.com/flightctl/test//tmp/repos/example/internal/cmd/weave/weave.go | func isBlank(line string) bool { return strings.TrimSpace(line) == "" } | main | ||||
function | flightctl/test | 0e6bd921-bf4f-4722-a392-11a89fe6760b | indented | ['"strings"'] | github.com/flightctl/test//tmp/repos/example/internal/cmd/weave/weave.go | func indented(line string) bool {
return strings.HasPrefix(line, " ") || strings.HasPrefix(line, "\t")
} | main | ||||
function | flightctl/test | c19eb70a-6c14-45e8-9c2d-bd2a9fb4794c | cleanListing | ['"strings"'] | github.com/flightctl/test//tmp/repos/example/internal/cmd/weave/weave.go | func cleanListing(text string) string {
lines := strings.Split(text, "\n")
// remove minimum number of leading tabs from all non-blank lines
tabs := 999
for i, line := range lines {
if strings.TrimSpace(line) == "" {
lines[i] = ""
} else {
if n := leadingTabs(line); n < tabs {
tabs = n
}
}
}
f... | main | ||||
function | flightctl/test | ccae3985-dd2b-44e7-8d4c-31c61a2e67bf | leadingTabs | github.com/flightctl/test//tmp/repos/example/internal/cmd/weave/weave.go | func leadingTabs(s string) int {
var i int
for i = 0; i < len(s); i++ {
if s[i] != '\t' {
break
}
}
return i
} | main | |||||
file | flightctl/test | a7c483d1-cdb2-4ee4-998b-2613f8acea0e | main.go | import (
"expvar"
"flag"
"fmt"
"html/template"
"log"
"net/http"
"sync"
"time"
) | github.com/flightctl/test//tmp/repos/example/outyet/main.go | // Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Outyet is a web server that announces whether or not a particular Go version
// has been tagged.
package main
import (
"expvar"
"flag"
"fmt"
"html/templ... | package main | ||||
function | flightctl/test | 9c04ff97-94d4-4096-8969-3af84fa0734d | main | ['"flag"', '"fmt"', '"log"', '"net/http"'] | github.com/flightctl/test//tmp/repos/example/outyet/main.go | func main() {
flag.Parse()
changeURL := fmt.Sprintf("%sgo%s", baseChangeURL, *version)
http.Handle("/", NewServer(*version, changeURL, *pollPeriod))
log.Printf("serving http://%s", *httpAddr)
log.Fatal(http.ListenAndServe(*httpAddr, nil))
} | main | ||||
function | flightctl/test | d43ac5e3-23bb-4ec8-8467-684357955d7b | NewServer | ['"time"'] | ['Server'] | github.com/flightctl/test//tmp/repos/example/outyet/main.go | func NewServer(version, url string, period time.Duration) *Server {
s := &Server{version: version, url: url, period: period}
go s.poll()
return s
} | main | |||
function | flightctl/test | 725692a9-b7d6-4183-9540-efc2b60c61e9 | poll | ['Server'] | github.com/flightctl/test//tmp/repos/example/outyet/main.go | func (s *Server) poll() {
for !isTagged(s.url) {
pollSleep(s.period)
}
s.mu.Lock()
s.yes = true
s.mu.Unlock()
pollDone()
} | main | ||||
function | flightctl/test | 071329df-84ea-43ff-b7aa-3b5320437c57 | isTagged | ['"log"', '"net/http"'] | github.com/flightctl/test//tmp/repos/example/outyet/main.go | func isTagged(url string) bool {
pollCount.Add(1)
r, err := http.Head(url)
if err != nil {
log.Print(err)
pollError.Set(err.Error())
pollErrorCount.Add(1)
return false
}
return r.StatusCode == http.StatusOK
} | main | ||||
function | flightctl/test | a5149f5e-679f-462c-afd1-abae04becd6a | ServeHTTP | ['"log"', '"net/http"'] | ['Server'] | github.com/flightctl/test//tmp/repos/example/outyet/main.go | func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request) {
hitCount.Add(1)
s.mu.RLock()
data := struct {
URL string
Version string
Yes bool
}{
s.url,
s.version,
s.yes,
}
s.mu.RUnlock()
err := tmpl.Execute(w, data)
if err != nil {
log.Print(err)
}
} | main | |||
file | flightctl/test | 62e5f929-b60a-491e-9c8a-cca9f01d5ed0 | main_test.go | import (
"net/http"
"net/http/httptest"
"strings"
"testing"
"time"
) | github.com/flightctl/test//tmp/repos/example/outyet/main_test.go | // Copyright 2023 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"net/http"
"net/http/httptest"
"strings"
"testing"
"time"
)
// statusHandler is an http.Handler that writes an empty response using... | package main | ||||
function | flightctl/test | b61bfc04-d335-49bf-ad50-7bde545bad6c | ServeHTTP | ['"net/http"'] | github.com/flightctl/test//tmp/repos/example/outyet/main_test.go | func (h *statusHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(int(*h))
} | main | ||||
function | flightctl/test | a8f38b5b-443b-4d80-8a05-b1947ca8cc74 | TestIsTagged | ['"net/http"', '"net/http/httptest"', '"testing"'] | github.com/flightctl/test//tmp/repos/example/outyet/main_test.go | func TestIsTagged(t *testing.T) {
// Set up a fake "Google Code" web server reporting 404 not found.
status := statusHandler(http.StatusNotFound)
s := httptest.NewServer(&status)
defer s.Close()
if isTagged(s.URL) {
t.Fatal("isTagged == true, want false")
}
// Change fake server status to 200 OK and try agai... | main | ||||
function | flightctl/test | e740f784-048a-4257-b6c3-aea380f84be4 | TestIntegration | ['"net/http"', '"net/http/httptest"', '"strings"', '"testing"', '"time"'] | github.com/flightctl/test//tmp/repos/example/outyet/main_test.go | func TestIntegration(t *testing.T) {
status := statusHandler(http.StatusNotFound)
ts := httptest.NewServer(&status)
defer ts.Close()
// Replace the pollSleep with a closure that we can block and unblock.
sleep := make(chan bool)
pollSleep = func(time.Duration) {
sleep <- true
sleep <- true
}
// Replace po... | main | ||||
file | flightctl/test | 29f32c71-6405-4ccf-8d6c-d29a9fd8e11f | json.go | import (
"encoding/json"
"fmt"
"mime"
"net/http"
) | github.com/flightctl/test//tmp/repos/example/ragserver/ragserver-genkit/json.go | // Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"encoding/json"
"fmt"
"mime"
"net/http"
)
// readRequestJSON expects req to have a JSON content type with a body that
// contains a ... | package main | ||||
function | flightctl/test | 921c10a9-3a49-496a-88d6-8b73a0539005 | readRequestJSON | ['"encoding/json"', '"fmt"', '"mime"', '"net/http"'] | github.com/flightctl/test//tmp/repos/example/ragserver/ragserver-genkit/json.go | func readRequestJSON(req *http.Request, target any) error {
contentType := req.Header.Get("Content-Type")
mediaType, _, err := mime.ParseMediaType(contentType)
if err != nil {
return err
}
if mediaType != "application/json" {
return fmt.Errorf("expect application/json Content-Type, got %s", mediaType)
}
dec... | main | ||||
function | flightctl/test | e479bdff-aa05-4e98-9deb-72a8a64918b3 | renderJSON | ['"encoding/json"', '"net/http"'] | github.com/flightctl/test//tmp/repos/example/ragserver/ragserver-genkit/json.go | func renderJSON(w http.ResponseWriter, v any) {
js, err := json.Marshal(v)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
w.Write(js)
} | main | ||||
file | flightctl/test | 92c15ce2-fe38-4326-beca-87c9da4336de | main.go | import (
"cmp"
"context"
"fmt"
"log"
"net/http"
"os"
"strings"
"github.com/firebase/genkit/go/ai"
"github.com/firebase/genkit/go/plugins/googleai"
"github.com/firebase/genkit/go/plugins/weaviate"
) | github.com/flightctl/test//tmp/repos/example/ragserver/ragserver-genkit/main.go | // Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Command ragserver is an HTTP server that implements RAG (Retrieval
// Augmented Generation) using the Gemini model and Weaviate, which
// are accessed using ... | package main | ||||
function | flightctl/test | 9c1aa2d4-f82c-4075-bbf3-54dc2eec1e00 | main | ['"cmp"', '"context"', '"log"', '"net/http"', '"os"', '"github.com/firebase/genkit/go/plugins/googleai"', '"github.com/firebase/genkit/go/plugins/weaviate"'] | ['ragServer'] | github.com/flightctl/test//tmp/repos/example/ragserver/ragserver-genkit/main.go | func main() {
ctx := context.Background()
err := googleai.Init(ctx, &googleai.Config{
APIKey: os.Getenv("GEMINI_API_KEY"),
})
if err != nil {
log.Fatal(err)
}
wvConfig := &weaviate.ClientConfig{
Scheme: "http",
Addr: "localhost:" + cmp.Or(os.Getenv("WVPORT"), "9035"),
}
_, err = weaviate.Init(ctx, wv... | main | |||
function | flightctl/test | 3a0fee89-44cd-467b-ac00-ada4340e725e | addDocumentsHandler | ['"fmt"', '"net/http"', '"github.com/firebase/genkit/go/ai"'] | ['ragServer'] | github.com/flightctl/test//tmp/repos/example/ragserver/ragserver-genkit/main.go | func (rs *ragServer) addDocumentsHandler(w http.ResponseWriter, req *http.Request) {
// Parse HTTP request from JSON.
type document struct {
Text string
}
type addRequest struct {
Documents []document
}
ar := &addRequest{}
err := readRequestJSON(req, ar)
if err != nil {
http.Error(w, err.Error(), http.Sta... | main | |||
function | flightctl/test | 714406c6-c283-4a97-854e-92d6de53a8f8 | queryHandler | ['"context"', '"fmt"', '"log"', '"net/http"', '"strings"', '"github.com/firebase/genkit/go/ai"', '"github.com/firebase/genkit/go/plugins/weaviate"'] | ['ragServer'] | github.com/flightctl/test//tmp/repos/example/ragserver/ragserver-genkit/main.go | func (rs *ragServer) queryHandler(w http.ResponseWriter, req *http.Request) {
// Parse HTTP request from JSON.
type queryRequest struct {
Content string
}
qr := &queryRequest{}
err := readRequestJSON(req, qr)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
// Find the most simi... | main | |||
file | flightctl/test | 1fdc20b5-21b0-4b4f-9d6d-b4a5bf5134db | json.go | import (
"encoding/json"
"fmt"
"mime"
"net/http"
) | github.com/flightctl/test//tmp/repos/example/ragserver/ragserver-langchaingo/json.go | // Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"encoding/json"
"fmt"
"mime"
"net/http"
)
// readRequestJSON expects req to have a JSON content type with a body that
// contains a ... | package main | ||||
function | flightctl/test | f0bbbce9-359a-477a-a83e-f6abc29ec354 | readRequestJSON | ['"encoding/json"', '"fmt"', '"mime"', '"net/http"'] | github.com/flightctl/test//tmp/repos/example/ragserver/ragserver-langchaingo/json.go | func readRequestJSON(req *http.Request, target any) error {
contentType := req.Header.Get("Content-Type")
mediaType, _, err := mime.ParseMediaType(contentType)
if err != nil {
return err
}
if mediaType != "application/json" {
return fmt.Errorf("expect application/json Content-Type, got %s", mediaType)
}
dec... | main | ||||
function | flightctl/test | 4fb0311a-3bd2-4cca-ad8b-4269c5db8569 | renderJSON | ['"encoding/json"', '"net/http"'] | github.com/flightctl/test//tmp/repos/example/ragserver/ragserver-langchaingo/json.go | func renderJSON(w http.ResponseWriter, v any) {
js, err := json.Marshal(v)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
w.Write(js)
} | main | ||||
file | flightctl/test | 35cea53c-e98d-45e5-8572-3cca3695c7a0 | main.go | import (
"cmp"
"context"
"fmt"
"log"
"net/http"
"os"
"strings"
"github.com/tmc/langchaingo/embeddings"
"github.com/tmc/langchaingo/llms"
"github.com/tmc/langchaingo/llms/googleai"
"github.com/tmc/langchaingo/schema"
"github.com/tmc/langchaingo/vectorstores/weaviate"
) | github.com/flightctl/test//tmp/repos/example/ragserver/ragserver-langchaingo/main.go | // Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Command ragserver is an HTTP server that implements RAG (Retrieval
// Augmented Generation) using the Gemini model and Weaviate, which
// are accessed using ... | package main | ||||
function | flightctl/test | 985d60f0-5223-4fa2-bfd3-6d28256cfcc7 | main | ['"cmp"', '"context"', '"log"', '"net/http"', '"os"', '"github.com/tmc/langchaingo/embeddings"', '"github.com/tmc/langchaingo/llms/googleai"', '"github.com/tmc/langchaingo/vectorstores/weaviate"'] | ['ragServer'] | github.com/flightctl/test//tmp/repos/example/ragserver/ragserver-langchaingo/main.go | func main() {
ctx := context.Background()
apiKey := os.Getenv("GEMINI_API_KEY")
geminiClient, err := googleai.New(ctx,
googleai.WithAPIKey(apiKey),
googleai.WithDefaultEmbeddingModel(embeddingModelName))
if err != nil {
log.Fatal(err)
}
emb, err := embeddings.NewEmbedder(geminiClient)
if err != nil {
lo... | main | |||
function | flightctl/test | 5793c33e-ec1b-4809-a407-6ad01f61d3b2 | addDocumentsHandler | ['"net/http"', '"github.com/tmc/langchaingo/embeddings"', '"github.com/tmc/langchaingo/schema"', '"github.com/tmc/langchaingo/vectorstores/weaviate"'] | ['ragServer'] | github.com/flightctl/test//tmp/repos/example/ragserver/ragserver-langchaingo/main.go | func (rs *ragServer) addDocumentsHandler(w http.ResponseWriter, req *http.Request) {
// Parse HTTP request from JSON.
type document struct {
Text string
}
type addRequest struct {
Documents []document
}
ar := &addRequest{}
err := readRequestJSON(req, ar)
if err != nil {
http.Error(w, err.Error(), http.St... | main | |||
function | flightctl/test | f8dd6cd2-2c89-4c0d-9e4d-2bbdf72af10c | queryHandler | ['"context"', '"fmt"', '"log"', '"net/http"', '"strings"', '"github.com/tmc/langchaingo/llms"'] | ['ragServer'] | github.com/flightctl/test//tmp/repos/example/ragserver/ragserver-langchaingo/main.go | func (rs *ragServer) queryHandler(w http.ResponseWriter, req *http.Request) {
// Parse HTTP request from JSON.
type queryRequest struct {
Content string
}
qr := &queryRequest{}
err := readRequestJSON(req, qr)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
// Find the most simi... | main | |||
file | flightctl/test | 82038242-4f01-4bdc-92b4-90447f4e7a57 | json.go | import (
"encoding/json"
"fmt"
"mime"
"net/http"
) | github.com/flightctl/test//tmp/repos/example/ragserver/ragserver/json.go | // Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
import (
"encoding/json"
"fmt"
"mime"
"net/http"
)
// readRequestJSON expects req to have a JSON content type with a body that
// contains a ... | package main | ||||
function | flightctl/test | 2bc28b4a-2c1b-4c7a-8f10-1d0ad00c4641 | readRequestJSON | ['"encoding/json"', '"fmt"', '"mime"', '"net/http"'] | github.com/flightctl/test//tmp/repos/example/ragserver/ragserver/json.go | func readRequestJSON(req *http.Request, target any) error {
contentType := req.Header.Get("Content-Type")
mediaType, _, err := mime.ParseMediaType(contentType)
if err != nil {
return err
}
if mediaType != "application/json" {
return fmt.Errorf("expect application/json Content-Type, got %s", mediaType)
}
dec... | main | ||||
function | flightctl/test | 81b51870-aeaf-483d-b4f8-b7f77e39a636 | renderJSON | ['"encoding/json"', '"net/http"'] | github.com/flightctl/test//tmp/repos/example/ragserver/ragserver/json.go | func renderJSON(w http.ResponseWriter, v any) {
js, err := json.Marshal(v)
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
return
}
w.Header().Set("Content-Type", "application/json")
w.Write(js)
} | main | ||||
file | flightctl/test | 08bd95d7-384f-4d08-8e71-77e8fdaccbf6 | main.go | import (
"cmp"
"context"
"fmt"
"log"
"net/http"
"os"
"strings"
"github.com/google/generative-ai-go/genai"
"github.com/weaviate/weaviate-go-client/v4/weaviate"
"github.com/weaviate/weaviate-go-client/v4/weaviate/graphql"
"github.com/weaviate/weaviate/entities/models"
"google.golang.org/api/option"
) | github.com/flightctl/test//tmp/repos/example/ragserver/ragserver/main.go | // Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
// Command ragserver is an HTTP server that implements RAG (Retrieval
// Augmented Generation) using the Gemini model and Weaviate. See the
// accompanying READ... | package main | ||||
function | flightctl/test | b6dd0373-aa2e-4a2c-b4df-0dc19324bd7d | main | ['"cmp"', '"context"', '"log"', '"net/http"', '"os"', '"github.com/google/generative-ai-go/genai"', '"google.golang.org/api/option"'] | ['ragServer'] | github.com/flightctl/test//tmp/repos/example/ragserver/ragserver/main.go | func main() {
ctx := context.Background()
wvClient, err := initWeaviate(ctx)
if err != nil {
log.Fatal(err)
}
apiKey := os.Getenv("GEMINI_API_KEY")
genaiClient, err := genai.NewClient(ctx, option.WithAPIKey(apiKey))
if err != nil {
log.Fatal(err)
}
defer genaiClient.Close()
server := &ragServer{
ctx: ... | main | |||
function | flightctl/test | 3f9c0d99-7ed3-4813-be13-69a998bf0960 | addDocumentsHandler | ['"log"', '"net/http"', '"github.com/google/generative-ai-go/genai"', '"github.com/weaviate/weaviate-go-client/v4/weaviate"', '"github.com/weaviate/weaviate/entities/models"'] | ['ragServer'] | github.com/flightctl/test//tmp/repos/example/ragserver/ragserver/main.go | func (rs *ragServer) addDocumentsHandler(w http.ResponseWriter, req *http.Request) {
// Parse HTTP request from JSON.
type document struct {
Text string
}
type addRequest struct {
Documents []document
}
ar := &addRequest{}
err := readRequestJSON(req, ar)
if err != nil {
http.Error(w, err.Error(), http.St... | main | |||
function | flightctl/test | 58e1e191-0ca6-4c69-a7e2-90f97622c4a8 | queryHandler | ['"context"', '"fmt"', '"log"', '"net/http"', '"strings"', '"github.com/google/generative-ai-go/genai"', '"github.com/weaviate/weaviate-go-client/v4/weaviate"', '"github.com/weaviate/weaviate-go-client/v4/weaviate/graphql"'] | ['ragServer'] | github.com/flightctl/test//tmp/repos/example/ragserver/ragserver/main.go | func (rs *ragServer) queryHandler(w http.ResponseWriter, req *http.Request) {
// Parse HTTP request from JSON.
type queryRequest struct {
Content string
}
qr := &queryRequest{}
err := readRequestJSON(req, qr)
if err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
// Embed the query co... | main | |||
function | flightctl/test | 43f1c333-7dc1-446a-b109-b209011c30d4 | decodeGetResults | ['"fmt"', '"github.com/weaviate/weaviate/entities/models"'] | github.com/flightctl/test//tmp/repos/example/ragserver/ragserver/main.go | func decodeGetResults(result *models.GraphQLResponse) ([]string, error) {
data, ok := result.Data["Get"]
if !ok {
return nil, fmt.Errorf("Get key not found in result")
}
doc, ok := data.(map[string]any)
if !ok {
return nil, fmt.Errorf("Get key unexpected type")
}
slc, ok := doc["Document"].([]any)
if !ok {
... | main | ||||
file | flightctl/test | f54cabd7-3f5b-48b3-a48c-2f6ae1eeddcc | weaviate.go | import (
"cmp"
"context"
"fmt"
"os"
"github.com/weaviate/weaviate-go-client/v4/weaviate"
"github.com/weaviate/weaviate/entities/models"
) | github.com/flightctl/test//tmp/repos/example/ragserver/ragserver/weaviate.go | // Copyright 2024 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package main
// Utilities for working with Weaviate.
import (
"cmp"
"context"
"fmt"
"os"
"github.com/weaviate/weaviate-go-client/v4/weaviate"
"github.c... | package main | ||||
function | flightctl/test | f0d09d3c-6fe3-4257-b163-fcc74467dbe0 | initWeaviate | ['"cmp"', '"context"', '"fmt"', '"os"', '"github.com/weaviate/weaviate-go-client/v4/weaviate"', '"github.com/weaviate/weaviate/entities/models"'] | github.com/flightctl/test//tmp/repos/example/ragserver/ragserver/weaviate.go | func initWeaviate(ctx context.Context) (*weaviate.Client, error) {
client, err := weaviate.NewClient(weaviate.Config{
Host: "localhost:" + cmp.Or(os.Getenv("WVPORT"), "9035"),
Scheme: "http",
})
if err != nil {
return nil, fmt.Errorf("initializing weaviate: %w", err)
}
// Create a new class (collection) i... | main | ||||
function | flightctl/test | 53d7f4a8-6fab-4024-a804-be4fda2f44f5 | combinedWeaviateError | ['"fmt"', '"github.com/weaviate/weaviate-go-client/v4/weaviate"', '"github.com/weaviate/weaviate/entities/models"'] | github.com/flightctl/test//tmp/repos/example/ragserver/ragserver/weaviate.go | func combinedWeaviateError(result *models.GraphQLResponse, err error) error {
if err != nil {
return err
}
if len(result.Errors) != 0 {
var ss []string
for _, e := range result.Errors {
ss = append(ss, e.Message)
}
return fmt.Errorf("weaviate error: %v", ss)
}
return nil
} | main | ||||
file | flightctl/test | 25f3316e-bc42-4036-98fd-1d02c7bb4b70 | indent_handler.go | import (
"context"
"fmt"
"io"
"log/slog"
"runtime"
"sync"
"time"
) | github.com/flightctl/test//tmp/repos/example/slog-handler-guide/indenthandler1/indent_handler.go | //go:build go1.21
package indenthandler
import (
"context"
"fmt"
"io"
"log/slog"
"runtime"
"sync"
"time"
)
// !+types
type IndentHandler struct {
opts Options
// TODO: state for WithGroup and WithAttrs
mu *sync.Mutex
out io.Writer
}
type Options struct {
// Level reports the minimum level to log.
// L... | package indenthandler | ||||
function | flightctl/test | 4d7c559b-5e7c-46a5-8456-f19855348226 | New | ['"io"', '"log/slog"', '"sync"'] | ['IndentHandler', 'Options'] | github.com/flightctl/test//tmp/repos/example/slog-handler-guide/indenthandler1/indent_handler.go | func New(out io.Writer, opts *Options) *IndentHandler {
h := &IndentHandler{out: out, mu: &sync.Mutex{}}
if opts != nil {
h.opts = *opts
}
if h.opts.Level == nil {
h.opts.Level = slog.LevelInfo
}
return h
} | indenthandler | |||
function | flightctl/test | 374c76c6-8837-4dc2-9678-026bf65d176e | Enabled | ['"context"', '"log/slog"'] | ['IndentHandler'] | github.com/flightctl/test//tmp/repos/example/slog-handler-guide/indenthandler1/indent_handler.go | func (h *IndentHandler) Enabled(ctx context.Context, level slog.Level) bool {
return level >= h.opts.Level.Level()
} | indenthandler | |||
function | flightctl/test | 1ba6d4e9-642b-411a-8516-78d208bdead2 | WithGroup | ['"log/slog"'] | ['IndentHandler'] | github.com/flightctl/test//tmp/repos/example/slog-handler-guide/indenthandler1/indent_handler.go | func (h *IndentHandler) WithGroup(name string) slog.Handler {
// TODO: implement.
return h
} | indenthandler | |||
function | flightctl/test | 9b4211de-9824-4539-9c16-e28283c29d1f | WithAttrs | ['"log/slog"'] | ['IndentHandler'] | github.com/flightctl/test//tmp/repos/example/slog-handler-guide/indenthandler1/indent_handler.go | func (h *IndentHandler) WithAttrs(attrs []slog.Attr) slog.Handler {
// TODO: implement.
return h
} | indenthandler | |||
function | flightctl/test | 15aff37e-66db-4280-81c7-440219db75fd | Handle | ['"context"', '"fmt"', '"log/slog"', '"runtime"'] | ['IndentHandler'] | github.com/flightctl/test//tmp/repos/example/slog-handler-guide/indenthandler1/indent_handler.go | func (h *IndentHandler) Handle(ctx context.Context, r slog.Record) error {
buf := make([]byte, 0, 1024)
if !r.Time.IsZero() {
buf = h.appendAttr(buf, slog.Time(slog.TimeKey, r.Time), 0)
}
buf = h.appendAttr(buf, slog.Any(slog.LevelKey, r.Level), 0)
if r.PC != 0 {
fs := runtime.CallersFrames([]uintptr{r.PC})
... | indenthandler | |||
function | flightctl/test | 6884d0e6-5ad6-4a1d-b405-7b3444e20a72 | appendAttr | ['"fmt"', '"log/slog"', '"time"'] | ['IndentHandler'] | github.com/flightctl/test//tmp/repos/example/slog-handler-guide/indenthandler1/indent_handler.go | func (h *IndentHandler) appendAttr(buf []byte, a slog.Attr, indentLevel int) []byte {
// Resolve the Attr's value before doing anything else.
a.Value = a.Value.Resolve()
// Ignore empty Attrs.
if a.Equal(slog.Attr{}) {
return buf
}
// Indent 4 spaces per level.
buf = fmt.Appendf(buf, "%*s", indentLevel*4, "")
... | indenthandler | |||
file | flightctl/test | 38cdcb41-e93b-4f1e-882f-bbc6ceee40b8 | indent_handler_test.go | import (
"bytes"
"regexp"
"testing"
"log/slog"
) | github.com/flightctl/test//tmp/repos/example/slog-handler-guide/indenthandler1/indent_handler_test.go | //go:build go1.21
package indenthandler
import (
"bytes"
"regexp"
"testing"
"log/slog"
)
func Test(t *testing.T) {
var buf bytes.Buffer
l := slog.New(New(&buf, nil))
l.Info("hello", "a", 1, "b", true, "c", 3.14, slog.Group("g", "h", 1, "i", 2), "d", "NO")
got := buf.String()
wantre := `time: [-0-9T:.]+Z?
l... | package indenthandler | ||||
function | flightctl/test | e7a6c869-a17f-4a33-9b4c-35e5ecaa52e8 | Test | ['"bytes"', '"regexp"', '"testing"', '"log/slog"'] | github.com/flightctl/test//tmp/repos/example/slog-handler-guide/indenthandler1/indent_handler_test.go | func Test(t *testing.T) {
var buf bytes.Buffer
l := slog.New(New(&buf, nil))
l.Info("hello", "a", 1, "b", true, "c", 3.14, slog.Group("g", "h", 1, "i", 2), "d", "NO")
got := buf.String()
wantre := `time: [-0-9T:.]+Z?
level: INFO
source: ".*/indent_handler_test.go:\d+"
msg: "hello"
a: 1
b: true
c: 3.14
g:
h: 1
... | indenthandler | ||||
file | flightctl/test | 085d42f6-b0f3-465b-90e0-386c02735e5c | indent_handler.go | import (
"context"
"fmt"
"io"
"log/slog"
"runtime"
"sync"
"time"
) | github.com/flightctl/test//tmp/repos/example/slog-handler-guide/indenthandler2/indent_handler.go | //go:build go1.21
package indenthandler
import (
"context"
"fmt"
"io"
"log/slog"
"runtime"
"sync"
"time"
)
// !+IndentHandler
type IndentHandler struct {
opts Options
goas []groupOrAttrs
mu *sync.Mutex
out io.Writer
}
//!-IndentHandler
type Options struct {
// Level reports the minimum level to log.... | package indenthandler | ||||
function | flightctl/test | ab002b84-6870-4a9f-8ef7-361cad29ee2b | New | ['"io"', '"log/slog"', '"sync"'] | ['IndentHandler', 'Options'] | github.com/flightctl/test//tmp/repos/example/slog-handler-guide/indenthandler2/indent_handler.go | func New(out io.Writer, opts *Options) *IndentHandler {
h := &IndentHandler{out: out, mu: &sync.Mutex{}}
if opts != nil {
h.opts = *opts
}
if h.opts.Level == nil {
h.opts.Level = slog.LevelInfo
}
return h
} | indenthandler | |||
function | flightctl/test | 42a6d0a2-33fe-400b-a7ac-99fb49ac1841 | Enabled | ['"context"', '"log/slog"'] | ['IndentHandler'] | github.com/flightctl/test//tmp/repos/example/slog-handler-guide/indenthandler2/indent_handler.go | func (h *IndentHandler) Enabled(ctx context.Context, level slog.Level) bool {
return level >= h.opts.Level.Level()
} | indenthandler | |||
function | flightctl/test | f32c8034-30e8-423e-9d0d-4afa23a0eaf6 | WithGroup | ['"log/slog"'] | ['IndentHandler', 'groupOrAttrs'] | github.com/flightctl/test//tmp/repos/example/slog-handler-guide/indenthandler2/indent_handler.go | func (h *IndentHandler) WithGroup(name string) slog.Handler {
if name == "" {
return h
}
return h.withGroupOrAttrs(groupOrAttrs{group: name})
} | indenthandler |
End of preview. Expand in Data Studio
No dataset card yet
- Downloads last month
- 3