- Populated .gitignore with Go-specific patterns - Created placeholder Go files with basic package structure: - bookstack.go: Client and Config setup - types.go: Data structures (Book, Page, Chapter, Shelf, SearchResult) - errors.go: Error handling types with sentinel errors - http.go: HTTP helper placeholder with ListOptions - books.go, pages.go, chapters.go, shelves.go, search.go: Service placeholders - Verified build succeeds with go build ./... - No external dependencies added (stdlib only) All files compile successfully and follow flat package structure.
63 lines
1.4 KiB
Go
63 lines
1.4 KiB
Go
package bookstack
|
|
|
|
import (
|
|
"net/http"
|
|
"time"
|
|
)
|
|
|
|
// Config holds configuration for the Bookstack API client.
|
|
type Config struct {
|
|
// BaseURL is the base URL of the Bookstack instance (e.g., "https://docs.example.com")
|
|
BaseURL string
|
|
|
|
// TokenID is the Bookstack API token ID
|
|
TokenID string
|
|
|
|
// TokenSecret is the Bookstack API token secret
|
|
TokenSecret string
|
|
|
|
// HTTPClient is the HTTP client to use for requests.
|
|
// If nil, a default client with 30s timeout will be used.
|
|
HTTPClient *http.Client
|
|
}
|
|
|
|
// Client is the main Bookstack API client.
|
|
type Client struct {
|
|
baseURL string
|
|
tokenID string
|
|
tokenSecret string
|
|
httpClient *http.Client
|
|
|
|
// Service instances
|
|
Books *BooksService
|
|
Pages *PagesService
|
|
Chapters *ChaptersService
|
|
Shelves *ShelvesService
|
|
Search *SearchService
|
|
}
|
|
|
|
// NewClient creates a new Bookstack API client.
|
|
func NewClient(cfg Config) *Client {
|
|
httpClient := cfg.HTTPClient
|
|
if httpClient == nil {
|
|
httpClient = &http.Client{
|
|
Timeout: 30 * time.Second,
|
|
}
|
|
}
|
|
|
|
c := &Client{
|
|
baseURL: cfg.BaseURL,
|
|
tokenID: cfg.TokenID,
|
|
tokenSecret: cfg.TokenSecret,
|
|
httpClient: httpClient,
|
|
}
|
|
|
|
// Initialize services
|
|
c.Books = &BooksService{client: c}
|
|
c.Pages = &PagesService{client: c}
|
|
c.Chapters = &ChaptersService{client: c}
|
|
c.Shelves = &ShelvesService{client: c}
|
|
c.Search = &SearchService{client: c}
|
|
|
|
return c
|
|
}
|