apttransport

package module
v0.0.0-...-d26b9db Latest Latest
Warning

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

Go to latest
Published: Mar 12, 2023 License: GPL-3.0 Imports: 13 Imported by: 0

README

aptTransport

Go API for creating transports for Debian's apt package manager(and it's relatives, etc)

Usage:

By default, the transport will use Go's default HTTP client, which will result in a transport which works for HTTP and HTTPS clearnet clients. This client is as simple as:

package main

import "github.com/eyedeekay/apttransport"

func main() {
    transport := &apttransport.AptMethod{}
    transport.Main = transport.DefaultMain
    transport.Main()
}

You can also hook into the process by creating a custom client. A client must implement the AptClient interface, which must have a Get function which returns an *http.Response. Of course, an HTTP Client works, here is an example which uses a SOCKS5 proxy:

package main

import "github.com/eyedeekay/apttransport"

func main() {
    transport := &apttransport.AptMethod{}
    transport.Main = transport.DefaultMain
    proxy, err := SOCKS5("tcp", "127.0.0.1:9050", nil, nil)
    if err != nil {
        panic(err)
    }
    transport.Client := &http.Client{
        Timeout: time.Duration(6) * time.Minute,
        Transport: &http.Transport{
            Dial: proxy.Dial,
        },
        CheckRedirect: nil,
    }
    transport.Main()
}

That is simply the type used for the response. The content of the Get function must compose an *http.Response to return. TODO: example which constructs an HTTP response from a bittorrent download.

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type AptClient

type AptClient interface {
	Get(url string) (*http.Response, error)
}

AptClient is an apt transport client which performs a download

type AptMessage

type AptMessage struct {
	Status     string
	StatusCode int
	Header     Header
	Exit       int
}

AptMessage is a message from the apt transport.

func (*AptMessage) String

func (m *AptMessage) String() string

String returns the apt message as a string

type AptMethod

type AptMethod struct {
	Client    AptClient
	AptString string
	Main      func()
}

AptMethod is a usable apt transport. It must be instantiated with a Main function. DefaultMain will work for almost all cases.

func (*AptMethod) DefaultMain

func (a *AptMethod) DefaultMain()

DefaultMain is a default Main function which will run all the registered functions or their corresponding defaults. If one wishes, the Main can be overwritten with a different function.

func (*AptMethod) GetAptString

func (a *AptMethod) GetAptString() string

GetAptString returns the protocol string used for the apt transport. defaults to the name of the executable+"://", or AptString if it is set. If an error occurs, it will return "http://"

func (*AptMethod) GetClient

func (a *AptMethod) GetClient() AptClient

GetClient returns the AptClient used for the apt transport. if no client is present, http.DefaultClient is used instead.

type Header map[string][]string

Header is a simple map of headers for an Apt message

func (Header) Add

func (h Header) Add(key, value string)

Add a header to the message.

func (Header) Get

func (h Header) Get(key string) string

Get a header from the message.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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