scan

package
v0.0.1 Latest Latest
Warning

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

Go to latest
Published: Apr 22, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Overview

Package scan manages API schema scanning and caching.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type API

type API struct {
	APIID   string  `json:"apiId"`
	APIName string  `json:"apiName"`
	APIType string  `json:"apiType"` // "list" or "object"
	Fields  []Field `json:"fields"`
}

API represents a scanned API endpoint.

func (*API) FieldNames

func (a *API) FieldNames() []string

FieldNames returns field IDs for an API.

type Cache

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

Cache manages scan result storage.

func NewCache

func NewCache() *Cache

NewCache creates a cache in the default directory.

func NewCacheWithDir

func NewCacheWithDir(dir string) *Cache

NewCacheWithDir creates a cache in a custom directory (for testing).

func (*Cache) IsFresh

func (c *Cache) IsFresh(serviceID string, ttl time.Duration) bool

IsFresh checks if the cache is within the TTL.

func (*Cache) Load

func (c *Cache) Load(serviceID string) (*Result, error)

Load reads the cached scan result for a service.

func (*Cache) Save

func (c *Cache) Save(result *Result) error

Save writes a scan result to cache.

type Field

type Field struct {
	FieldID  string `json:"fieldId"`
	Name     string `json:"name"`
	Kind     string `json:"kind"`
	Required bool   `json:"required"`
}

Field represents a field in an API schema.

type Result

type Result struct {
	ServiceID string    `json:"serviceId"`
	ScannedAt time.Time `json:"scannedAt"`
	APIs      []API     `json:"apis"`
	Hash      string    `json:"hash"`
}

Result holds the complete scan output for a service.

func (*Result) EndpointNames

func (r *Result) EndpointNames() []string

EndpointNames returns all endpoint names.

func (*Result) FindAPI

func (r *Result) FindAPI(endpoint string) *API

FindAPI returns the API info for a given endpoint, or nil.

func (*Result) ListCount

func (r *Result) ListCount() int

ListCount returns the number of list-type APIs.

func (*Result) ObjectCount

func (r *Result) ObjectCount() int

ObjectCount returns the number of object-type APIs.

type Scanner

type Scanner struct {
	Client *api.Client
	OnAPI  func(apiID, apiType string, fieldCount int) // progress callback
}

Scanner fetches API schemas from microCMS management API.

func (*Scanner) Execute

func (s *Scanner) Execute(ctx context.Context, serviceID string) (*Result, error)

Execute performs a full scan of the service's APIs.

Jump to

Keyboard shortcuts

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