package main

import (
	"strings"

	"github.com/sheenobu/go-xco"
)

func main() {
	opts := xco.Options{
		Name:         "sms.example.com",
		SharedSecret: "secret shared with the XMPP server",
		Address:      "127.0.0.1:5347",
	}
	c, err := xco.NewComponent(opts)
	if err != nil {
		panic(err)
	}

	// Uppercase Echo Component
	c.MessageHandler = xco.BodyResponseHandler(func(msg *xco.Message) (string, error) {
		return strings.ToUpper(msg.Body), nil
	})

	c.Run()
}

package main

import (
	"fmt"
	"os"
	"strings"

	"github.com/BurntSushi/toml"
	"github.com/sheenobu/go-xco"
)

type StaticConfig struct {
	Xmpp StaticConfigXmpp `toml:"xmpp"`
}

type StaticConfigXmpp struct {
	Host   string `toml:"host"`
	Name   string `toml:"name"`
	Port   int    `toml:"port"`
	Secret string `toml:"secret"`
}

func main() {
	config := new(StaticConfig)
	_, err := toml.DecodeFile(os.Args[1], &config)
	if err != nil {
		panic(err)
	}

	opts := xco.Options{
		Name:         config.Xmpp.Name,
		SharedSecret: config.Xmpp.Secret,
		Address:      fmt.Sprintf("%s:%d", config.Xmpp.Host, config.Xmpp.Port),
	}
	c, err := xco.NewComponent(opts)
	if err != nil {
		panic(err)
	}

	// Uppercase Echo Component
	c.MessageHandler = xco.BodyResponseHandler(func(msg *xco.Message) (string, error) {
		return strings.ToUpper(msg.Body), nil
	})

	c.Run()
}

Move configuration to a file
Move configuration to a file

Instead of hard coding details about the XMPP server and the SMS
component, load them from a config file.  The name of the config file
must be given as the first argument on the command line.  The config
file format is TOML.  It should look something like this:

  [xmpp]
  host = "127.0.0.1"
  port = 5347
  name = "sms.example.com"
  secret = "secret shared between server and component"
