https://github.com/rdhillbb/messagefile
API to get messages from a file for prompts and or error message or general user messages
https://github.com/rdhillbb/messagefile
golang messagefile prompts prompts-template
Last synced: 2 months ago
JSON representation
API to get messages from a file for prompts and or error message or general user messages
- Host: GitHub
- URL: https://github.com/rdhillbb/messagefile
- Owner: rdhillbb
- Created: 2024-12-22T11:17:16.000Z (6 months ago)
- Default Branch: main
- Last Pushed: 2024-12-22T11:32:44.000Z (6 months ago)
- Last Synced: 2025-02-14T19:51:48.078Z (4 months ago)
- Topics: golang, messagefile, prompts, prompts-template
- Language: Go
- Homepage:
- Size: 1.95 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Message File Parser
A simple Go package for parsing structured XML message files and retrieving messages using a section:message key format.
## Installation
```bash
go get github.com/rdhillbb/messagefile
```## Usage
The package provides a simple API to retrieve messages from an XML message file. The message file should be named `messagefile.xml` and be in the following format:
```xml
Message content goes here
```
### API Reference
#### GetMSG(messageKey string) (string, error)
Retrieves a message using a colon-separated section and message type key.
- `messageKey`: Format is "section:message"
- Returns: The message content and any error encountered### Example
```go
package mainimport (
"fmt"
"github.com/yourusername/messagefile"
)func main() {
// Retrieve a message
msg, err := messagefile.GetMSG("utilmessages:query_rewrite")
if err != nil {
fmt.Printf("Error: %v\n", err)
return
}
fmt.Printf("Message: %s\n", msg)
}
```### Message File Example
```xml
You are tasked with enhancing a user's query.
Here is the user's original query:
%s
```
## Error Handling
The package returns errors for:
- Invalid message key format
- Missing message file
- Invalid XML structure
- Section not found
- Message not found