Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go kosu/rpc #174

Merged
merged 6 commits into from Jul 23, 2019
Merged
Changes from 1 commit
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

Next

go-kosu: add doctool PoC

  • Loading branch information
gchaincl committed Jul 17, 2019
commit 44b8809d680878d41cdc0dded08da6d9cf366cb5
@@ -0,0 +1,44 @@
package main

import (
"encoding/json"
"fmt"
"go/doc"
"go/parser"
"go/token"
"log"
"os"
)

type DocEntry struct {
Method string `json:"method"`
Text string `json:"text"`
}

func main() {
if len(os.Args) < 2 {
fmt.Println("Usage: doctool <path>")
return
}

fset := token.NewFileSet()
pkgs, err := parser.ParseDir(fset, os.Args[1], nil, parser.ParseComments)
if err != nil {
log.Fatal(err)
}

docs := []DocEntry{}
pkg := doc.New(pkgs["rpc"], os.Args[1], doc.AllDecls)
for _, t := range pkg.Types {
for _, m := range t.Methods {
docs = append(docs, DocEntry{Method: m.Name, Text: m.Doc})
}
}

text, err := json.MarshalIndent(docs, "", " ")
if err != nil {
log.Fatal(err)
}

fmt.Printf("%s\n", text)
}
@@ -0,0 +1,8 @@
package rpc

// Server is a RPC server
type Server struct {
}

// Subscribe subscribes to something
func (s *Server) Subscribe() {}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.