Ascii2d

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

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

Go to latest
Published: Jul 3, 2026 License: MIT Imports: 13 Imported by: 0

README

Ascii2d-go

要求

  • Go 1.25+
  • 运行中的 FlareSolverr 服务端

安装

go get github.com/Miuzarte/Ascii2d-go

示例

package main

import (
    "context"
    "fmt"
    fs "github.com/Miuzarte/FlareSolverr-go"
    a2d "github.com/Miuzarte/Ascii2d-go"
)

// using `https://ascii2d.net` when empty
const OVERRIDE_HOST = ""

func main() {
    fsClient := fs.NewClient("http://127.0.0.1:8191/v1")
    client := a2d.NewClient(OVERRIDE_HOST, fsClient)

    // can be:
    // url.(string): using .Get()
    // filepath.(string), data.([]byte), r.(io.Reader): using .Post()
    var img any
    color, bovw, err := client.Search(context.Background(), img)
    if err != nil {
        panic(err)
    }

    printResult := func(res a2d.Result) {
        switch res.ResultType {
        case "color":
            fmt.Println("色合検索")
        case "bovw":
            fmt.Println("特徴検索")
        }
        fmt.Printf("thumbnail: %s", res.Thumbnail)
        fmt.Printf("%s - %s\n", res.Title, res.Author)
        fmt.Println(res.Url)
        fmt.Println(res.AuthorUrl)
    }

    printResult(color)
    printResult(bovw)
}

Documentation

Index

Constants

View Source
const (
	API_HOST         = `https://ascii2d.net`
	API_SEARCH_FILE  = `/search/file`
	API_SEARCH_URL   = `/search/url`
	API_RESULT_COLOR = `/search/color`
	API_RESULT_BOVW  = `/search/bovw`
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	Host               string
	FlareSolverrClient *fs.Client
	NumResults         int // [TODO] 显式指定返回的结果数量
	// contains filtered or unexported fields
}

func NewClient

func NewClient(overrideHost string, fsClient *fs.Client) *Client

func (*Client) Download

func (c *Client) Download(ctx context.Context, res Result) ([]byte, error)

Download 通过搜索时缓存的 FlareSolverr 凭证下载缩略图,返回图片字节 若缓存为空则现取一次;调用点应对 error 做回退处理

func (*Client) Get

func (c *Client) Get(ctx context.Context, imgUrl string) (color Result, bovw Result, err error)

func (*Client) Post

func (c *Client) Post(ctx context.Context, imgData []byte) (color Result, bovw Result, err error)

func (*Client) Search

func (c *Client) Search(ctx context.Context, image any) (color Result, bovw Result, err error)

type Result

type Result struct {
	Title     string
	Author    string
	Url       string
	AuthorUrl string
	Thumbnail string

	ResultUrl  string
	ResultType string // "color" | "bovw"

	Success              bool
	IsRegisteredManually bool
}

Jump to

Keyboard shortcuts

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