nntp

package module
v0.0.0-...-0c87ee9 Latest Latest
Warning

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

Go to latest
Published: Jun 7, 2020 License: MIT Imports: 9 Imported by: 1

README

go nntp stream

package main

import (
	"context"
	"log"
	"time"

	nntp "github.com/skaji/go-nntp-stream"
)

func main() {
	config := nntp.StreamConfig{
		Addr:    "nntp.perl.org:119",
		Group:   "perl.cpan.uploads",
		Tick:    30 * time.Second,
		Timeout: 20 * time.Second,
	}

	stream := nntp.Stream(context.Background(), config)
	for event := range stream {
		switch event.Type {
		case nntp.EventTypeArticle:
			article := event.Article
			log.Println(article.ID, article.Header.Get("Subject"))
		default:
			log.Println(event.Type, event.Message)
		}
	}
}

See also

https://github.com/dustin/go-nntp

Author

Shoichi Kaji

License

MIT

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Stream

func Stream(ctx context.Context, config StreamConfig) <-chan *Event

Types

type Article

type Article struct {
	ID     int
	Header mail.Header
	Body   []byte
}

type Client

type Client struct {
	// contains filtered or unexported fields
}

func Connect

func Connect(ctx context.Context, addr string) (*Client, error)

func (*Client) Article

func (c *Client) Article(id int) (*Article, error)

func (*Client) Close

func (c *Client) Close() error

func (*Client) Group

func (c *Client) Group(name string) (*Group, error)

func (*Client) SetDeadline

func (c *Client) SetDeadline(ctx context.Context) func()

type Event

type Event struct {
	Type    EventType
	Message string
	Article *Article
}

type EventType

type EventType string
var (
	EventTypeArticle EventType = "article"
	EventTypeDebug   EventType = "debug"
	EventTypeInfo    EventType = "info"
	EventTypeError   EventType = "error"
)

type Group

type Group struct {
	High int
}

type StreamConfig

type StreamConfig struct {
	Addr    string
	Group   string
	Offset  int
	Tick    time.Duration
	Timeout time.Duration
}

Jump to

Keyboard shortcuts

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