An open API service indexing awesome lists of open source software.

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

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 main

import (
"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