Documentation ¶
Index ¶
- func GetPathInt(ctx *gin.Context, name string) (int, error)
- func SetupRoutes(node *masa.OracleNode) *gin.Engine
- type API
- func (api *API) CreateNewTopicHandler() gin.HandlerFunc
- func (api *API) GetAds() gin.HandlerFunc
- func (api *API) GetFromDHT() gin.HandlerFunc
- func (api *API) GetLLMModelsHandler() gin.HandlerFunc
- func (api *API) GetNodeDataHandler() gin.HandlerFunc
- func (api *API) GetNodeHandler() gin.HandlerFunc
- func (api *API) GetPeerAddresses() gin.HandlerFunc
- func (api *API) GetPeersHandler() gin.HandlerFunc
- func (api *API) GetPublicKeysHandler() gin.HandlerFunc
- func (api *API) GetTest() gin.HandlerFunc
- func (api *API) NodeStatusPageHandler() gin.HandlerFunc
- func (api *API) PostAd() gin.HandlerFunc
- func (api *API) PostNodeStatusHandler() gin.HandlerFunc
- func (api *API) PostToDHT() gin.HandlerFunc
- func (api *API) PostToTopicHandler() gin.HandlerFunc
- func (api *API) PublishPublicKeyHandler() gin.HandlerFunc
- func (api *API) SearchTweetsAndAnalyzeSentiment() gin.HandlerFunc
- func (api *API) SearchTweetsProfile() gin.HandlerFunc
- func (api *API) SearchTweetsRecent() gin.HandlerFunc
- func (api *API) SearchTweetsTrends() gin.HandlerFunc
- func (api *API) SearchWebAndAnalyzeSentiment() gin.HandlerFunc
- func (api *API) SubscribeToAds() gin.HandlerFunc
- func (api *API) WebData() gin.HandlerFunc
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func GetPathInt ¶
GetPathInt converts the path parameter with name to an int. It returns the int value and nil error if the path parameter is present and a valid integer. It returns 0 and a formatted error if the path parameter is missing or not a valid integer.
func SetupRoutes ¶
func SetupRoutes(node *masa.OracleNode) *gin.Engine
SetupRoutes configures the router with all API routes. It takes an OracleNode instance and returns a configured gin.Engine. Routes are added for peers, ads, subscriptions, node data, public keys, topics, the DHT, node status, and serving HTML pages. Middleware is added for CORS and templates.
Types ¶
type API ¶
type API struct {
Node *masa.OracleNode
}
func NewAPI ¶
func NewAPI(node *masa.OracleNode) *API
NewAPI creates a new API instance with the given OracleNode.
func (*API) CreateNewTopicHandler ¶
func (api *API) CreateNewTopicHandler() gin.HandlerFunc
CreateNewTopicHandler creates a new topic with a given name and subscribes a handler to it.
func (*API) GetAds ¶
func (api *API) GetAds() gin.HandlerFunc
func (*API) GetFromDHT ¶
func (api *API) GetFromDHT() gin.HandlerFunc
GetFromDHT handles GET requests to retrieve data from the DHT given a key. It looks up the key in the DHT, unmarshals the value into a SharedData struct, and returns the data in the response.
func (*API) GetLLMModelsHandler ¶
func (api *API) GetLLMModelsHandler() gin.HandlerFunc
GetLLMModelsHandler returns a gin.HandlerFunc that retrieves the available LLM models. It does not expect any request parameters. The handler returns a JSON response containing an array of supported LLM model names.
func (*API) GetNodeDataHandler ¶
func (api *API) GetNodeDataHandler() gin.HandlerFunc
GetNodeDataHandler handles GET requests to retrieve paginated node data from the node tracker. It parses the page number and page size from the request path, retrieves all node data from the node tracker, calculates pagination details like total pages based on page size, and returns a page of node data in the response.
func (*API) GetNodeHandler ¶
func (api *API) GetNodeHandler() gin.HandlerFunc
GetNodeHandler handles GET requests to retrieve node data for a specific peer ID. It extracts the peer ID from the request URL parameters, retrieves the node data from the node tracker, calculates additional uptime info, and returns the node data in the response.
func (*API) GetPeerAddresses ¶
func (api *API) GetPeerAddresses() gin.HandlerFunc
GetPeerAddresses handles GET requests to retrieve the list of peer addresses from the node's libp2p host network. It gets the list of connected peers, finds the multiaddrs for connections to each peer, and returns the peer IDs mapped to their addresses.
func (*API) GetPeersHandler ¶
func (api *API) GetPeersHandler() gin.HandlerFunc
GetPeersHandler handles GET requests to retrieve the list of peer IDs from the DHT routing table. It retrieves the routing table from the node's DHT instance, extracts the peer IDs, and returns them in the response.
func (*API) GetPublicKeysHandler ¶
func (api *API) GetPublicKeysHandler() gin.HandlerFunc
GetPublicKeysHandler handles the endpoint to retrieve all known public keys. It gets the public key subscription handler from the PubSub manager, extracts the public keys, and returns them in the response.
func (*API) GetTest ¶
func (api *API) GetTest() gin.HandlerFunc
func (*API) NodeStatusPageHandler ¶
func (api *API) NodeStatusPageHandler() gin.HandlerFunc
NodeStatusPageHandler handles HTTP requests to show the node status page. It retrieves the node data from the node tracker, formats it, and renders an HTML page displaying the node's status and uptime info.
func (*API) PostAd ¶
func (api *API) PostAd() gin.HandlerFunc
func (*API) PostNodeStatusHandler ¶
func (api *API) PostNodeStatusHandler() gin.HandlerFunc
PostNodeStatusHandler allows posting a message to the Topic
func (*API) PostToDHT ¶
func (api *API) PostToDHT() gin.HandlerFunc
PostToDHT handles POST requests to write data to the DHT. It expects a JSON body with "key" and "value" fields. The "key" is used to store the data in the DHT under /db/key. The "value" is marshalled to JSON and written to the DHT. Returns 200 OK on success with the key in the response. Returns 400 Bad Request on invalid request or JSON errors.
func (*API) PostToTopicHandler ¶
func (api *API) PostToTopicHandler() gin.HandlerFunc
PostToTopicHandler allows posting a message to a specified topic.
func (*API) PublishPublicKeyHandler ¶
func (api *API) PublishPublicKeyHandler() gin.HandlerFunc
PublishPublicKeyHandler handles the /publickey endpoint. It retrieves the node's public key, signs the public key with the private key, creates a public key message with the key info, signs it, and publishes it to the public key topic. This allows other nodes to obtain this node's public key.
func (*API) SearchTweetsAndAnalyzeSentiment ¶
func (api *API) SearchTweetsAndAnalyzeSentiment() gin.HandlerFunc
SearchTweetsAndAnalyzeSentiment method adjusted to match the pattern Models Supported:
"all"
claude-3-opus-20240229 claude-3-sonnet-20240229 claude-3-haiku-20240307 gpt-4 gpt-4-turbo-preview gpt-3.5-turbo llama2 llama3 mistral gemma mixtral openchat neural-chat
func (*API) SearchTweetsProfile ¶
func (api *API) SearchTweetsProfile() gin.HandlerFunc
SearchTweetsProfile returns a gin.HandlerFunc that processes a request to search for tweets from a specific user profile. It expects a URL parameter "username" representing the Twitter username to search for. The handler validates the username, ensuring it is provided. If the request is valid, it attempts to scrape the user's profile and tweets. On success, it returns the scraped profile information in a JSON response. On failure, it returns an appropriate error message and HTTP status code.
func (*API) SearchTweetsRecent ¶
func (api *API) SearchTweetsRecent() gin.HandlerFunc
SearchTweetsRecent returns a gin.HandlerFunc that processes a request to search for tweets based on a query and count. It expects a JSON body with fields "query" (string) and "count" (int), representing the search query and the number of tweets to return, respectively. The handler validates the request body, ensuring the query is not empty and the count is positive. If the request is valid, it attempts to scrape tweets using the specified query and count. On success, it returns the scraped tweets in a JSON response. On failure, it returns an appropriate error message and HTTP status code.
func (*API) SearchTweetsTrends ¶
func (api *API) SearchTweetsTrends() gin.HandlerFunc
SearchTweetsTrends returns a gin.HandlerFunc that processes a request to search for trending tweets. It does not expect any request parameters. The handler attempts to scrape trending tweets using the ScrapeTweetsByTrends function. On success, it returns the scraped tweets in a JSON response. On failure, it returns an appropriate error message and HTTP status code.
func (*API) SearchWebAndAnalyzeSentiment ¶
func (api *API) SearchWebAndAnalyzeSentiment() gin.HandlerFunc
SearchWebAndAnalyzeSentiment returns a gin.HandlerFunc that processes web search requests and performs sentiment analysis. It first validates the request body for required fields such as URL, Depth, and Model. If the Model is set to "all", it iterates through all available models to perform sentiment analysis on the web content fetched from the specified URL. The function responds with the sentiment analysis results in JSON format. Models Supported:
"all" "claude-3-opus-20240229" "claude-3-sonnet-20240229" "claude-3-haiku-20240307" "gpt-4" "gpt-4-turbo-preview" "gpt-3.5-turbo"
func (*API) SubscribeToAds ¶
func (api *API) SubscribeToAds() gin.HandlerFunc
func (*API) WebData ¶
func (api *API) WebData() gin.HandlerFunc
WebData returns a gin.HandlerFunc that processes web scraping requests. It expects a JSON body with fields "url" (string) and "depth" (int), representing the URL to scrape and the depth of the scrape, respectively. The handler validates the request body, ensuring the URL is not empty and the depth is positive. If the node has not staked, it returns an error indicating the node cannot participate. On a valid request, it attempts to scrape web data using the specified URL and depth. On success, it returns the scraped data in a sanitized JSON response. On failure, it returns an appropriate error message and HTTP status code.