本文整理汇总了Golang中kythe/io/kythe/go/util/kytheuri.ToString函数的典型用法代码示例。如果您正苦于以下问题:Golang ToString函数的具体用法?Golang ToString怎么用?Golang ToString使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了ToString函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: SourceFromEntries
// SourceFromEntries returns a new Source from the given a set of entries with
// the same source VName.
func SourceFromEntries(entries []*spb.Entry) *Source {
if len(entries) == 0 {
return nil
}
src := &Source{
Ticket: kytheuri.ToString(entries[0].Source),
Facts: make(map[string][]byte),
Edges: make(map[string][]string),
}
edgeTargets := make(map[string]stringset.Set)
for _, e := range entries {
if graphstore.IsEdge(e) {
tgts, ok := edgeTargets[e.EdgeKind]
if !ok {
tgts = stringset.New()
edgeTargets[e.EdgeKind] = tgts
}
tgts.Add(kytheuri.ToString(e.Target))
} else {
src.Facts[e.FactName] = e.FactValue
}
}
for kind, targets := range edgeTargets {
src.Edges[kind] = targets.Slice()
sort.Strings(src.Edges[kind])
}
return src
}
示例2: TestDecorations
func TestDecorations(t *testing.T) {
xs := newService(t, testEntries)
reply, err := xs.Decorations(ctx, &xpb.DecorationsRequest{
Location: &xpb.Location{
Ticket: kytheuri.ToString(testFileVName),
},
SourceText: true,
References: true,
Filter: []string{"**"},
})
if err != nil {
t.Fatalf("Error fetching decorations for %+v: %v", testFileVName, err)
}
if string(reply.SourceText) != testFileContent {
t.Errorf("Incorrect file content: %q; Expected: %q", string(reply.SourceText), testFileContent)
}
if reply.Encoding != testFileEncoding {
t.Errorf("Incorrect file encoding: %q; Expected: %q", reply.Encoding, testFileEncoding)
}
expectedRefs := []*xpb.DecorationsReply_Reference{
{
SourceTicket: kytheuri.ToString(testAnchorVName),
TargetTicket: kytheuri.ToString(testAnchorTargetVName),
Kind: schema.RefEdge,
AnchorStart: &xpb.Location_Point{
ByteOffset: 1,
LineNumber: 1,
ColumnOffset: 1,
},
AnchorEnd: &xpb.Location_Point{
ByteOffset: 4,
LineNumber: 1,
ColumnOffset: 4,
},
},
}
if err := testutil.DeepEqual(sortRefs(expectedRefs), sortRefs(reply.Reference)); err != nil {
t.Error(err)
}
expectedNodes := nodesToInfos(testNodes[4:6])
if err := testutil.DeepEqual(expectedNodes, sortInfos(reply.Node)); err != nil {
t.Error(err)
}
}
示例3: nodesToTickets
func nodesToTickets(nodes []*node) []string {
var tickets []string
for _, n := range nodes {
tickets = append(tickets, kytheuri.ToString(n.Source))
}
return tickets
}
示例4: nodesToInfos
func nodesToInfos(nodes []*node) map[string]*cpb.NodeInfo {
m := make(map[string]*cpb.NodeInfo)
for _, n := range nodes {
m[kytheuri.ToString(n.Source)] = n.Info()
}
return m
}
示例5: TestForPackage
func TestForPackage(t *testing.T) {
tests := []struct {
path string
ticket string
isRoot bool
}{
{path: "bytes", ticket: "kythe://golang.org?lang=go?path=bytes#%3Apkg%3A", isRoot: true},
{path: "go/types", ticket: "kythe://golang.org?lang=go?path=go/types#%3Apkg%3A", isRoot: true},
{path: "golang.org/x/net/context", ticket: "kythe://golang.org/x/net?lang=go?path=context#%3Apkg%3A"},
{path: "code.google.com/p/foo.bar/baz", ticket: "kythe://code.google.com/p/foo?lang=go?path=baz?root=bar#%3Apkg%3A"},
{path: "fuzzy1.googlecode.com/alpha", ticket: "kythe://fuzzy1.googlecode.com?lang=go?path=alpha#%3Apkg%3A"},
{path: "github.com/google/kythe/foo", ticket: "kythe://github.com/google/kythe?lang=go?path=foo#%3Apkg%3A"},
{path: "bitbucket.org/zut/alors/non", ticket: "kythe://bitbucket.org/zut/alors?lang=go?path=non#%3Apkg%3A"},
{path: "launchpad.net/~frood/blee/blor", ticket: "kythe://launchpad.net/~frood/blee?lang=go?path=blor#%3Apkg%3A"},
{path: "golang.org/x/net/context", ticket: "kythe://golang.org/x/net?lang=go?path=context#%3Apkg%3A"},
}
for _, test := range tests {
pkg := &build.Package{
ImportPath: test.path,
Goroot: test.isRoot,
}
got := ForPackage("", pkg)
gotTicket := kytheuri.ToString(got)
if gotTicket != test.ticket {
t.Errorf(`ForPackage("", [%s]): got %q, want %q`, test.path, gotTicket, test.ticket)
}
}
}
示例6: collectNodes
func collectNodes(nodeEntries <-chan *spb.Entry) <-chan *srvpb.Node {
nodes := make(chan *srvpb.Node)
go func() {
var (
node *srvpb.Node
vname *spb.VName
)
for e := range nodeEntries {
if node != nil && !compare.VNamesEqual(e.Source, vname) {
nodes <- node
node = nil
vname = nil
}
if node == nil {
vname = e.Source
ticket := kytheuri.ToString(vname)
node = &srvpb.Node{Ticket: ticket}
}
node.Fact = append(node.Fact, &srvpb.Node_Fact{
Name: e.FactName,
Value: e.FactValue,
})
}
if node != nil {
nodes <- node
}
close(nodes)
}()
return nodes
}
示例7: Sources
// Sources constructs a new Source for every contiguous set of entries sharing
// the same Source, calling f for each.
func Sources(rd stream.EntryReader, f func(*ipb.Source) error) error {
var source *spb.VName
var src *ipb.Source
if err := rd(func(entry *spb.Entry) error {
if src != nil && !compare.VNamesEqual(source, entry.Source) {
if err := f(src); err != nil {
return err
}
src = nil
}
if src == nil {
source = entry.Source
src = &ipb.Source{
Ticket: kytheuri.ToString(entry.Source),
Facts: make(map[string][]byte),
EdgeGroups: make(map[string]*ipb.Source_EdgeGroup),
}
}
AppendEntry(src, entry)
return nil
}); err != nil {
return err
}
if src != nil {
return f(src)
}
return nil
}
示例8: AppendEntry
// AppendEntry adds the given Entry to the Source's facts or edges. It is
// assumed that src.Ticket == kytheuri.ToString(e.Source).
func AppendEntry(src *ipb.Source, e *spb.Entry) {
if graphstore.IsEdge(e) {
kind, ordinal, _ := edges.ParseOrdinal(e.EdgeKind)
group, ok := src.EdgeGroups[kind]
if !ok {
group = &ipb.Source_EdgeGroup{}
src.EdgeGroups[kind] = group
}
ticket := kytheuri.ToString(e.Target)
ord := int32(ordinal)
for _, edge := range group.Edges {
if edge.Ticket == ticket && edge.Ordinal == ord {
// Don't add duplicate edge
return
}
}
group.Edges = append(group.Edges, &ipb.Source_Edge{
Ticket: ticket,
Ordinal: ord,
})
} else {
src.Facts[e.FactName] = e.FactValue
}
}
示例9: EdgeSet
func (n *node) EdgeSet() *xpb.EdgeSet {
var groups []*xpb.EdgeSet_Group
for kind, targets := range n.Edges {
var tickets []string
for _, target := range targets {
tickets = append(tickets, kytheuri.ToString(target))
}
groups = append(groups, &xpb.EdgeSet_Group{
Kind: kind,
TargetTicket: tickets,
})
}
return &xpb.EdgeSet{
SourceTicket: kytheuri.ToString(n.Source),
Group: groups,
}
}
示例10: writeEdges
func writeEdges(ctx context.Context, t table.Proto, edges <-chan *spb.Entry, maxEdgePageSize int) error {
defer drainEntries(edges) // ensure channel is drained on errors
temp, err := tempTable("edge.groups")
if err != nil {
return fmt.Errorf("failed to create temporary table: %v", err)
}
edgeGroups := &table.KVProto{temp}
defer func() {
if err := edgeGroups.Close(ctx); err != nil {
log.Println("Error closing edge groups table: %v", err)
}
}()
log.Println("Writing temporary edges table")
var (
src *spb.VName
kind string
targets stringset.Set
)
for e := range edges {
if src != nil && (!compare.VNamesEqual(e.Source, src) || kind != e.EdgeKind) {
if err := writeWithReverses(ctx, edgeGroups, kytheuri.ToString(src), kind, targets.Slice()); err != nil {
return err
}
src = nil
}
if src == nil {
src = e.Source
kind = e.EdgeKind
targets = stringset.New()
}
targets.Add(kytheuri.ToString(e.Target))
}
if src != nil {
if err := writeWithReverses(ctx, edgeGroups, kytheuri.ToString(src), kind, targets.Slice()); err != nil {
return err
}
}
return writeEdgePages(ctx, t, edgeGroups, maxEdgePageSize)
}
示例11: nodesToEdgeSets
func nodesToEdgeSets(nodes []*node) map[string]*gpb.EdgeSet {
sets := make(map[string]*gpb.EdgeSet)
for _, n := range nodes {
set := n.EdgeSet()
if len(set.Groups) > 0 {
sets[kytheuri.ToString(n.Source)] = set
}
}
return sets
}
示例12: Info
func (n *node) Info() *xpb.NodeInfo {
info := &xpb.NodeInfo{
Ticket: kytheuri.ToString(n.Source),
}
for name, val := range n.Facts {
info.Fact = append(info.Fact, &xpb.Fact{
Name: name,
Value: []byte(val),
})
}
return info
}
示例13: node
func node(v *spb.VName, facts ...string) *srvpb.Node {
if len(facts)%2 != 0 {
panic("odd number of facts")
}
n := &srvpb.Node{Ticket: kytheuri.ToString(v)}
for i := 0; i < len(facts); i += 2 {
n.Fact = append(n.Fact, &srvpb.Node_Fact{
Name: facts[i],
Value: []byte(facts[i+1]),
})
}
return n
}
示例14: TestDecorations
func TestDecorations(t *testing.T) {
xs := newService(t, testEntries)
reply, err := xs.Decorations(ctx, &xpb.DecorationsRequest{
Location: &xpb.Location{
Ticket: kytheuri.ToString(testFileVName),
},
SourceText: true,
References: true,
})
if err != nil {
t.Fatalf("Error fetching decorations for %+v: %v", testFileVName, err)
}
if string(reply.SourceText) != testFileContent {
t.Errorf("Incorrect file content: %q; Expected: %q", string(reply.SourceText), testFileContent)
}
if reply.Encoding != testFileEncoding {
t.Errorf("Incorrect file encoding: %q; Expected: %q", reply.Encoding, testFileEncoding)
}
expectedRefs := []*xpb.DecorationsReply_Reference{
{
SourceTicket: kytheuri.ToString(testAnchorVName),
TargetTicket: kytheuri.ToString(testAnchorTargetVName),
Kind: schema.RefEdge,
},
}
if !reflect.DeepEqual(sortRefs(reply.Reference), sortRefs(expectedRefs)) {
t.Errorf("Got %v; Expected references %v", reply.Reference, expectedRefs)
}
refNodes := testNodes[4:6]
expectedNodes := nodesToInfos(refNodes)
if !reflect.DeepEqual(sortInfos(reply.Node), expectedNodes) {
t.Errorf("Got %v; Expected nodes %v", reply.Node, expectedNodes)
}
}
示例15: EdgeSet
func (n *node) EdgeSet() *gpb.EdgeSet {
groups := make(map[string]*gpb.EdgeSet_Group)
for kind, targets := range n.Edges {
var edges []*gpb.EdgeSet_Group_Edge
for ordinal, target := range targets {
edges = append(edges, &gpb.EdgeSet_Group_Edge{
TargetTicket: kytheuri.ToString(target),
Ordinal: int32(ordinal),
})
}
groups[kind] = &gpb.EdgeSet_Group{
Edge: edges,
}
}
return &gpb.EdgeSet{
Groups: groups,
}
}