File: gof3_topic.go

package info (click to toggle)
golang-code.forgejo-f3-gof3 3.11.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 1,952 kB
  • sloc: sh: 100; makefile: 65
file content (38 lines) | stat: -rw-r--r-- 925 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright Earl Warren <contact@earl-warren.org>
// Copyright Loïc Dachary <loic@dachary.org>
// SPDX-License-Identifier: MIT

package sdk

import (
	"fmt"
	"time"
)

type Topic struct {
	ID        int64      `json:"id"`
	Name      string     `json:"topic_name"`
	RepoCount int        `json:"repo_count"`
	Created   *time.Time `json:"created_at"`
	Updated   *time.Time `json:"updated_at"`
}

type SearchTopicsOptions struct {
	ListOptions
	Keyword string
}

func (opt *SearchTopicsOptions) QueryEncode() string {
	query := opt.getURLQuery()
	if opt.Keyword != "" {
		query.Add("q", opt.Keyword)
	}
	return query.Encode()
}

func (c *Client) SearchTopics(opt SearchTopicsOptions) ([]*Topic, *Response, error) {
	opt.setDefaults()
	topics := make([]*Topic, 0, opt.PageSize)
	resp, err := c.getParsedResponse("GET", fmt.Sprintf("/topics/search?%s", opt.getURLQuery().Encode()), nil, nil, &topics)
	return topics, resp, err
}