nntpcli

package module
v0.0.0-...-2aa86ca Latest Latest
Warning

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

Go to latest
Published: Dec 8, 2024 License: MIT Imports: 16 Imported by: 0

README

nntpcli

A NNTP client with the fastest yenc support.

Installation

To install the nntpcli package, you can use go get:

go get github.com/javi11/nntpcli

Usage

Here is a simple example of how to use the nntpcli package:

package main

import (
    "context"
    "fmt"
    "log"
    "os"
    "strings"
    "time"

    "github.com/javi11/nntpcli"
)

func main() {
    client := nntpcli.New()
    conn, err := client.Dial(context.Background(), "news.example.com", 119, time.Now().Add(5*time.Second))
    if err != nil {
        log.Fatal(err)
    }
    defer conn.Close()

    err = conn.Authenticate("username", "password")
    if err != nil {
        log.Fatal(err)
    }

    err = conn.JoinGroup("misc.test")
    if err != nil {
        log.Fatal(err)
    }

    fmt.Println("Joined group:", conn.CurrentJoinedGroup())

    // Example of Body command
    body, err := os.Create("article_body.txt")
    if err != nil {
        log.Fatal(err)
    }
    defer body.Close()

    _, err = conn.BodyDecoded("<message-id>", body, 0)
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println("Article body saved to article_body.txt")

    // Example of Post command
    postContent := `From: <nobody@example.com>
Newsgroups: misc.test
Subject: Test Post
Message-Id: <1234>
Organization: nntpcli

This is a test post.
`
    err = conn.Post(strings.NewReader(postContent))
    if err != nil {
        log.Fatal(err)
    }
    fmt.Println("Article posted successfully")
}

Development Setup

To set up the project for development, follow these steps:

  1. Clone the repository:
git clone https://github.com/javi11/nntpcli.git
cd nntpcli
  1. Install dependencies:
go mod download
  1. Run tests:
make test
  1. Lint the code:
make lint
  1. Generate mocks and other code:
make generate

Contributing

Contributions are welcome! Please open an issue or submit a pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

Documentation

Overview

Package nntpcli is a generated GoMock package.

Package nntp provides base NNTP definitions.

Package nntpcli is a generated GoMock package.

Index

Constants

View Source
const (
	Unknown             = PostingStatus(0)
	PostingPermitted    = PostingStatus('y')
	PostingNotPermitted = PostingStatus('n')
	PostingModerated    = PostingStatus('m')
)

PostingStatus values.

View Source
const ArticleNotFoundErrCode = 430
View Source
const CanNotJoinGroup = 411
View Source
const NumberOfStatResParams = 3
View Source
const SegmentAlreadyExistsErrCode = 441
View Source
const ToManyConnectionsErrCode = 502

Variables

View Source
var (
	ErrCapabilitiesUnpopulated = errors.New("capabilities unpopulated")
	ErrNoSuchCapability        = errors.New("no such capability")
	ErrNilNttpConn             = errors.New("nil nntp connection")
)

Functions

func IsArticleNotFoundError

func IsArticleNotFoundError(err error) bool

func IsRetryableError

func IsRetryableError(err error) bool

Types

type Article

type Article struct {
	// The article's headers
	Header textproto.MIMEHeader
	// The article's body
	Body io.Reader
	// Number of bytes in the article body (used by OVER/XOVER)
	Bytes int
	// Number of lines in the article body (used by OVER/XOVER)
	Lines int
}

An Article that may appear in one or more groups.

func (*Article) MessageID

func (a *Article) MessageID() string

MessageID provides convenient access to the article's Message ID.

type Client

type Client interface {
	Dial(
		ctx context.Context,
		host string,
		port int,
		maxAgeTime time.Time,
	) (Connection, error)
	DialTLS(
		ctx context.Context,
		host string,
		port int,
		insecureSSL bool,
		maxAgeTime time.Time,
	) (Connection, error)
}

func New

func New(options ...Option) Client

type Config

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

type Connection

type Connection interface {
	io.Closer
	Authenticate(username, password string) (err error)
	JoinGroup(name string) error
	BodyDecoded(msgId string, w io.Writer, discard int64) (int64, error)
	Post(r io.Reader) error
	CurrentJoinedGroup() string
	MaxAgeTime() time.Time
	Stat(msgId string) (int, error)
	Capabilities() ([]string, error)
}

func NewFakeConnection

func NewFakeConnection() Connection

type Group

type Group struct {
	Name        string
	Description string
	Count       int64
	High        int64
	Low         int64
	Posting     PostingStatus
}

Group represents a usenet newsgroup.

type MockClient

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

MockClient is a mock of Client interface.

func NewMockClient

func NewMockClient(ctrl *gomock.Controller) *MockClient

NewMockClient creates a new mock instance.

func (*MockClient) Dial

func (m *MockClient) Dial(ctx context.Context, host string, port int, maxAgeTime time.Time) (Connection, error)

Dial mocks base method.

func (*MockClient) DialTLS

func (m *MockClient) DialTLS(ctx context.Context, host string, port int, insecureSSL bool, maxAgeTime time.Time) (Connection, error)

DialTLS mocks base method.

func (*MockClient) EXPECT

func (m *MockClient) EXPECT() *MockClientMockRecorder

EXPECT returns an object that allows the caller to indicate expected use.

type MockClientMockRecorder

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

MockClientMockRecorder is the mock recorder for MockClient.

func (*MockClientMockRecorder) Dial

func (mr *MockClientMockRecorder) Dial(ctx, host, port, maxAgeTime interface{}) *gomock.Call

Dial indicates an expected call of Dial.

func (*MockClientMockRecorder) DialTLS

func (mr *MockClientMockRecorder) DialTLS(ctx, host, port, insecureSSL, maxAgeTime interface{}) *gomock.Call

DialTLS indicates an expected call of DialTLS.

type MockConnection

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

MockConnection is a mock of Connection interface.

func NewMockConnection

func NewMockConnection(ctrl *gomock.Controller) *MockConnection

NewMockConnection creates a new mock instance.

func (*MockConnection) Authenticate

func (m *MockConnection) Authenticate(username, password string) error

Authenticate mocks base method.

func (*MockConnection) BodyDecoded

func (m *MockConnection) BodyDecoded(msgId string, w io.Writer, discard int64) (int64, error)

BodyDecoded mocks base method.

func (*MockConnection) Capabilities

func (m *MockConnection) Capabilities() ([]string, error)

Capabilities mocks base method.

func (*MockConnection) Close

func (m *MockConnection) Close() error

Close mocks base method.

func (*MockConnection) CurrentJoinedGroup

func (m *MockConnection) CurrentJoinedGroup() string

CurrentJoinedGroup mocks base method.

func (*MockConnection) EXPECT

EXPECT returns an object that allows the caller to indicate expected use.

func (*MockConnection) JoinGroup

func (m *MockConnection) JoinGroup(name string) error

JoinGroup mocks base method.

func (*MockConnection) MaxAgeTime

func (m *MockConnection) MaxAgeTime() time.Time

MaxAgeTime mocks base method.

func (*MockConnection) Post

func (m *MockConnection) Post(r io.Reader) error

Post mocks base method.

func (*MockConnection) Stat

func (m *MockConnection) Stat(msgId string) (int, error)

Stat mocks base method.

type MockConnectionMockRecorder

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

MockConnectionMockRecorder is the mock recorder for MockConnection.

func (*MockConnectionMockRecorder) Authenticate

func (mr *MockConnectionMockRecorder) Authenticate(username, password interface{}) *gomock.Call

Authenticate indicates an expected call of Authenticate.

func (*MockConnectionMockRecorder) BodyDecoded

func (mr *MockConnectionMockRecorder) BodyDecoded(msgId, w, discard interface{}) *gomock.Call

BodyDecoded indicates an expected call of BodyDecoded.

func (*MockConnectionMockRecorder) Capabilities

func (mr *MockConnectionMockRecorder) Capabilities() *gomock.Call

Capabilities indicates an expected call of Capabilities.

func (*MockConnectionMockRecorder) Close

func (mr *MockConnectionMockRecorder) Close() *gomock.Call

Close indicates an expected call of Close.

func (*MockConnectionMockRecorder) CurrentJoinedGroup

func (mr *MockConnectionMockRecorder) CurrentJoinedGroup() *gomock.Call

CurrentJoinedGroup indicates an expected call of CurrentJoinedGroup.

func (*MockConnectionMockRecorder) JoinGroup

func (mr *MockConnectionMockRecorder) JoinGroup(name interface{}) *gomock.Call

JoinGroup indicates an expected call of JoinGroup.

func (*MockConnectionMockRecorder) MaxAgeTime

func (mr *MockConnectionMockRecorder) MaxAgeTime() *gomock.Call

MaxAgeTime indicates an expected call of MaxAgeTime.

func (*MockConnectionMockRecorder) Post

func (mr *MockConnectionMockRecorder) Post(r interface{}) *gomock.Call

Post indicates an expected call of Post.

func (*MockConnectionMockRecorder) Stat

func (mr *MockConnectionMockRecorder) Stat(msgId interface{}) *gomock.Call

Stat indicates an expected call of Stat.

type Option

type Option func(*Config)

func WithLogger

func WithLogger(log *slog.Logger) Option

func WithTimeout

func WithTimeout(timeout time.Duration) Option

type PostingStatus

type PostingStatus byte

PostingStatus type for groups.

func (PostingStatus) String

func (ps PostingStatus) String() string

type TimeData

type TimeData struct {
	Milliseconds int64
	Bytes        int
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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