Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/myriad-dreamin/go-parse-package
get the package info of function/variable at runtime
https://github.com/myriad-dreamin/go-parse-package
Last synced: about 1 month ago
JSON representation
get the package info of function/variable at runtime
- Host: GitHub
- URL: https://github.com/myriad-dreamin/go-parse-package
- Owner: Myriad-Dreamin
- Created: 2019-11-02T08:58:55.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2020-01-17T22:45:54.000Z (almost 5 years ago)
- Last Synced: 2024-06-20T17:42:48.616Z (5 months ago)
- Language: Go
- Homepage:
- Size: 5.86 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# go-parse-package
get the package info of function/variable at runtime## Installation
```bash
go get github.com/Myriad-Dreamin/go-parse-package
```
or just import it in your package## Functions
### runtime parser
```go
func FuncDescription(f interface{}) (string, error)
```
`FuncDescription` Get description of a function```go
func InterfaceDescription(i interface{}) (string, error)
```
`InterfaceDescription` Get description of an interface
if v where v in `InterfaceDescription(v)` is an interface you should call it with `InterfaceDescription(&v)````go
func TypeInterfaceDescription(t reflect.Type) (string, error)
```
`TypeInterfaceDescription` Get description of a specified type### parsing tools
```go
func ParsePackage(fileName string, mode parser.Mode) (*ast.Package, error)
```
`ParsePackage` Parse the package of a file with `parse.Mode````go
func ParsePackageDir(fileDir string, mode parser.Mode) (*ast.Package, error)
```
`ParsePackageDir` Parse the package of all files in directory with `parse.Mode````go
func ParsePackageDoc(path string) (*doc.Package, error)
```
`ParsePackageDoc` Parse the package by path```go
func ParsePackageDocDir(pkgDir string) (*doc.Package, error)
```
`ParsePackageDocDir` Parse the package of all files in directory```go
func ParsePackageDocFile(fileName string) (*doc.Package, error)
```
`ParsePackageDocFile` Parse the package of a file```go
func ParsePackageName(path string) (string, error)
```
`ParsePackageName` Parse the package by path```go
func ParsePackageNameDir(pkgDir string) (string, error)
```
`ParsePackageNameDir` Parse the package name of all files in directory```go
func ParsePackageNameFile(fileName string) (string, error)
```
`ParsePackageNameFile` Parse the package name of a file## Types
```go
type PackageMapper func(packageName string) (packagePath string)
``````go
func SetPackageMapper(xGetPackagePath PackageMapper) PackageMapper
```
`SetPackageMapper` provide package path mapper of a interface's package
you must set your own package mapper before calling function `TypeInterfaceDescription`
for example```go
import "github.com/Myriad-Dreamin/go-magic-package/instance"
... //(in your function)
SetPackageMapper(instance.Get)
TypeInterfaceDescription(reflect.Typeof(&MyInterface))
```