-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(About) Load about from .json in services directory
- Loading branch information
Showing
9 changed files
with
574 additions
and
54 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,68 +1,28 @@ | ||
package controllers | ||
|
||
import ( | ||
"AREA/internal/models" | ||
"AREA/internal/pkg" | ||
"github.com/gin-gonic/gin" | ||
"net/http" | ||
"strconv" | ||
"time" | ||
) | ||
|
||
type action struct { | ||
Name string `json:"name"` | ||
Description string `json:"description"` | ||
} | ||
|
||
type reaction struct { | ||
Name string `json:"name"` | ||
Description string `json:"description"` | ||
} | ||
|
||
type service struct { | ||
Name string `json:"name"` | ||
Actions []action `json:"actions"` | ||
Reaction []reaction `json:"reaction"` | ||
} | ||
|
||
func getServiceList() []service { | ||
return []service{ | ||
{ | ||
Name: "mail", | ||
Actions: []action{ | ||
{ | ||
Name: "send", | ||
Description: "send mail", | ||
}, | ||
}, | ||
Reaction: []reaction{ | ||
{ | ||
Name: "receive", | ||
Description: "receive mail", | ||
}, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
// About godoc | ||
// @Summary About | ||
// @Description about | ||
// @Tags about | ||
// @Accept json | ||
// @Produce json | ||
// @Success 200 {msg} string | ||
// @Router /about.json [get] | ||
// About handler with cached service data | ||
func About(c *gin.Context) { | ||
var msg struct { | ||
Client struct { | ||
Host string `json:"host"` | ||
} `json:"client"` | ||
Server struct { | ||
CurrentTime string `json:"current_time"` | ||
Services []service | ||
CurrentTime string `json:"current_time"` | ||
Services []models.ServiceList `json:"services"` | ||
} `json:"server"` | ||
} | ||
|
||
msg.Client.Host = c.ClientIP() | ||
msg.Server.CurrentTime = strconv.FormatInt(time.Now().Unix(), 10) | ||
msg.Server.Services = getServiceList() | ||
msg.Server.Services = pkg.CachedServices | ||
c.JSON(http.StatusOK, msg) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package models | ||
|
||
type parameter struct { | ||
Name string `json:"name"` | ||
Description string `json:"description"` | ||
Type string `json:"type"` | ||
} | ||
|
||
type action struct { | ||
Name string `json:"name"` | ||
Description string `json:"description"` | ||
Parameters []parameter `json:"parameters"` | ||
} | ||
|
||
type reaction struct { | ||
Name string `json:"name"` | ||
Description string `json:"description"` | ||
Parameters []parameter `json:"parameters"` | ||
} | ||
|
||
type ServiceList struct { | ||
Name string `json:"name"` | ||
Actions []action `json:"actions"` | ||
Reaction []reaction `json:"reactions"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package pkg | ||
|
||
import ( | ||
"AREA/internal/consts" | ||
"AREA/internal/models" | ||
"github.com/goccy/go-json" | ||
"io/ioutil" | ||
"log" | ||
"path/filepath" | ||
) | ||
|
||
var CachedServices []models.ServiceList | ||
|
||
func InitServiceList() { | ||
files, err := filepath.Glob(filepath.Join(consts.ServiceFileDirectory, "*.json")) | ||
if err != nil { | ||
log.Println("Error loading service files:", err) | ||
return | ||
} | ||
|
||
var services []models.ServiceList | ||
for _, file := range files { | ||
data, err := ioutil.ReadFile(file) | ||
if err != nil { | ||
log.Printf("Error reading file %s: %v", file, err) | ||
continue | ||
} | ||
|
||
var srv models.ServiceList | ||
err = json.Unmarshal(data, &srv) | ||
if err != nil { | ||
log.Printf("Error unmarshalling file %s: %v", file, err) | ||
continue | ||
} | ||
|
||
services = append(services, srv) | ||
} | ||
|
||
CachedServices = services | ||
log.Printf("Loaded %d services at startup.", len(CachedServices)) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
{ | ||
"name": "discord", | ||
"actions": [ | ||
{ | ||
"name": "A new message is sent", | ||
"description": "Triggered when a new message is sent in a Discord channel.", | ||
"parameters": [ | ||
{ | ||
"name": "channel_id", | ||
"description": "The ID of the Discord channel where the message was sent.", | ||
"type": "string" | ||
}, | ||
{ | ||
"name": "message_content", | ||
"description": "The content of the message.", | ||
"type": "string" | ||
}, | ||
{ | ||
"name": "author_id", | ||
"description": "The ID of the user who sent the message.", | ||
"type": "string" | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "A message is deleted", | ||
"description": "Triggered when a message is deleted in a Discord channel.", | ||
"parameters": [ | ||
{ | ||
"name": "channel_id", | ||
"description": "The ID of the Discord channel where the message was deleted.", | ||
"type": "string" | ||
}, | ||
{ | ||
"name": "message_id", | ||
"description": "The ID of the deleted message.", | ||
"type": "string" | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "A message is edited", | ||
"description": "Triggered when a message is edited in a Discord channel.", | ||
"parameters": [ | ||
{ | ||
"name": "channel_id", | ||
"description": "The ID of the Discord channel where the message was edited.", | ||
"type": "string" | ||
}, | ||
{ | ||
"name": "message_id", | ||
"description": "The ID of the edited message.", | ||
"type": "string" | ||
}, | ||
{ | ||
"name": "new_content", | ||
"description": "The new content of the edited message.", | ||
"type": "string" | ||
} | ||
] | ||
} | ||
], | ||
"reactions": [ | ||
{ | ||
"name": "Send a message in a channel", | ||
"description": "Send a message to a specific Discord channel.", | ||
"parameters": [ | ||
{ | ||
"name": "channel_id", | ||
"description": "The ID of the Discord channel where the message should be sent.", | ||
"type": "string" | ||
}, | ||
{ | ||
"name": "message_content", | ||
"description": "The content of the message to send.", | ||
"type": "string" | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "Delete a message", | ||
"description": "Delete a specific message in a Discord channel.", | ||
"parameters": [ | ||
{ | ||
"name": "channel_id", | ||
"description": "The ID of the Discord channel where the message should be deleted.", | ||
"type": "string" | ||
}, | ||
{ | ||
"name": "message_id", | ||
"description": "The ID of the message to delete.", | ||
"type": "string" | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "Pin/Unpin a message", | ||
"description": "Pin or unpin a specific message in a Discord channel.", | ||
"parameters": [ | ||
{ | ||
"name": "channel_id", | ||
"description": "The ID of the Discord channel where the message should be pinned or unpinned.", | ||
"type": "string" | ||
}, | ||
{ | ||
"name": "message_id", | ||
"description": "The ID of the message to pin or unpin.", | ||
"type": "string" | ||
}, | ||
{ | ||
"name": "is_pinned", | ||
"description": "Set to true to pin the message, or false to unpin it.", | ||
"type": "bool" | ||
} | ||
] | ||
} | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
{ | ||
"name": "google", | ||
"actions": [ | ||
{ | ||
"name": "Email Received", | ||
"description": "Triggered when a new email is received in your Gmail inbox.", | ||
"parameters": [ | ||
{ | ||
"name": "sender_email", | ||
"description": "The email address of the sender.", | ||
"type": "string" | ||
}, | ||
{ | ||
"name": "subject", | ||
"description": "The subject of the email.", | ||
"type": "string" | ||
}, | ||
{ | ||
"name": "received_date", | ||
"description": "The date and time when the email was received.", | ||
"type": "string" | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "Email Sent", | ||
"description": "Triggered when an email is sent from your Gmail account.", | ||
"parameters": [ | ||
{ | ||
"name": "recipient_email", | ||
"description": "The email address of the recipient.", | ||
"type": "string" | ||
}, | ||
{ | ||
"name": "subject", | ||
"description": "The subject of the sent email.", | ||
"type": "string" | ||
}, | ||
{ | ||
"name": "sent_date", | ||
"description": "The date and time when the email was sent.", | ||
"type": "string" | ||
} | ||
] | ||
} | ||
], | ||
"reactions": [ | ||
{ | ||
"name": "Send an Email", | ||
"description": "Send an email using your Gmail account.", | ||
"parameters": [ | ||
{ | ||
"name": "recipient_email", | ||
"description": "The email address of the recipient.", | ||
"type": "string" | ||
}, | ||
{ | ||
"name": "subject", | ||
"description": "The subject of the email.", | ||
"type": "string" | ||
}, | ||
{ | ||
"name": "body", | ||
"description": "The content of the email.", | ||
"type": "string" | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "Reply to an Email", | ||
"description": "Reply to a specific email in your Gmail inbox.", | ||
"parameters": [ | ||
{ | ||
"name": "email_id", | ||
"description": "The unique ID of the email to reply to.", | ||
"type": "string" | ||
}, | ||
{ | ||
"name": "reply_body", | ||
"description": "The content of the reply.", | ||
"type": "string" | ||
} | ||
] | ||
}, | ||
{ | ||
"name": "Marked as read/unread", | ||
"description": "Mark an email as read or unread in your Gmail inbox.", | ||
"parameters": [ | ||
{ | ||
"name": "email_id", | ||
"description": "The unique ID of the email to mark.", | ||
"type": "string" | ||
}, | ||
{ | ||
"name": "is_read", | ||
"description": "Set to true to mark as read, or false to mark as unread.", | ||
"type": "bool" | ||
} | ||
] | ||
} | ||
] | ||
} |
Oops, something went wrong.