getdoc

package module
v0.42.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 18, 2024 License: MIT Imports: 17 Imported by: 1

README

getdoc

Documentation extract utilities for Telegram schema using goquery.

Used by gotd/td for embedding documentation to generated code.

Parsed documentation

Parsed documentation for 133 layer is available as 133.json with schema.

Example

Latest schema is embedded to package, so you can just use it:

doc, err := getdoc.Load(133)
if err != nil {
    panic(err)
}
fmt.Printf("Layer %d, constructors: %d\n", doc.Index.Layer, len(doc.Constructors))
// Output:
// Layer 133, constructors: 926

Reference

Please use official documentation, it is for humans, this package is not.

Documentation

Overview

Package getdoc provides a way to transform Telegram TL documentation into machine-readable format.

Index

Examples

Constants

View Source
const (
	CategoryType        = "type"
	CategoryConstructor = "constructor"
	CategoryMethod      = "method"
)
View Source
const LayerLatest = 170

LayerLatest is id of the latest layer.

Variables

View Source
var ErrNotFound = errors.New("layer not found")

ErrNotFound means that current package version does not support requested layer.

View Source
var Layers = []int{
	121,
	133,
	138,
	139,
	144,
	145,
	155,
	158,
	164,
	167,
	170,
}

Layers is list of supported layers.

Functions

func LayerExists

func LayerExists(layer int) bool

LayerExists returns true if layer is included in package.

Types

type Category

type Category struct {
	Name   string   `json:"name"`
	Values []string `json:"values"`
}

Category index.

type Constructor

type Constructor struct {
	Name        string                      `json:"name"`
	Description []string                    `json:"description,omitempty"`
	Links       []string                    `json:"links,omitempty"`
	Fields      map[string]ParamDescription `json:"fields,omitempty"`
}

Constructor represents constructor documentation.

func ParseConstructor

func ParseConstructor(reader io.Reader) (*Constructor, error)

ParseConstructor parses html documentation from reader and produces Constructor.

type Doc

type Doc struct {
	Index Index `json:"index"`

	Constructors map[string]Constructor `json:"constructors"`
	Types        map[string]Type        `json:"types"`
	Methods      map[string]Method      `json:"methods"`
	Errors       map[string]Error       `json:"errors"`
}

Doc represents full documentation description.

func Extract

func Extract(ctx context.Context, d Downloader) (*Doc, error)

Extract uses Downloader to extract documentation.

func ExtractLayer added in v0.4.0

func ExtractLayer(ctx context.Context, layer int, d Downloader) (*Doc, error)

ExtractLayer uses Downloader to extract documentation of specified layer.

func Load

func Load(layer int) (*Doc, error)

Load layer documentation.

Example
package main

import (
	"fmt"

	"github.com/gotd/getdoc"
)

func main() {
	layer := 133
	if !getdoc.LayerExists(121) {
		panic("not exists")
	}
	if !getdoc.LayerExists(133) {
		panic("not exists")
	}
	doc, err := getdoc.Load(layer)
	if err != nil {
		panic(err)
	}

	fmt.Printf("Layer %d, constructors: %d\n", doc.Index.Layer, len(doc.Constructors))
}
Output:

Layer 133, constructors: 926

type Downloader

type Downloader interface {
	Get(ctx context.Context, layer int, key string) ([]byte, error)
}

Downloader abstracts documentation fetching.

type Error

type Error struct {
	Code        int    `json:"code"`
	Type        string `json:"type"`
	Description string `json:"description,omitempty"`
}

Error represent possible error documentation.

type Index

type Index struct {
	Layer      int        `json:"layer"`
	Categories []Category `json:"categories"`
}

Index of schema.

func ParseIndex

func ParseIndex(reader io.Reader) (*Index, error)

ParseIndex parses schema index documentation from reader.

type Method

type Method struct {
	Name        string                      `json:"name"`
	Description []string                    `json:"description,omitempty"`
	Links       []string                    `json:"links,omitempty"`
	Parameters  map[string]ParamDescription `json:"parameters,omitempty"`
	Errors      []Error                     `json:"errors,omitempty"`
	BotCanUse   bool                        `json:"bot_can_use,omitempty"`
}

Method represents method documentation.

func ParseMethod

func ParseMethod(reader io.Reader) (*Method, error)

ParseMethod extracts method documentation from reader.

type ParamDescription added in v0.2.0

type ParamDescription struct {
	Name        string   `json:"name"`
	Description string   `json:"description"`
	Links       []string `json:"links,omitempty"`
}

type Type

type Type struct {
	Name        string   `json:"name"`
	Description []string `json:"description,omitempty"`
	Links       []string `json:"links,omitempty"`
}

Type represents type (aka class) documentation.

func ParseType

func ParseType(reader io.Reader) (*Type, error)

ParseType parses Type documentation from reader.

Directories

Path Synopsis
cmd
getdoc
Binary getdoc extracts Telegram documentation to json file.
Binary getdoc extracts Telegram documentation to json file.
dl
Package dl implements documentation downloading facility.
Package dl implements documentation downloading facility.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL