server/pkg/config/trdl_channels.go

Summary

Maintainability
A
0 mins
Test Coverage
F
0%
package config

import (
    "fmt"

    "gopkg.in/yaml.v2"
)

const (
    DefaultTrdlChannelsPath = "trdl_channels.yaml"
)

type TrdlChannels struct {
    Groups []TrdlGroup `yaml:"groups,omitempty"`
}

type TrdlGroup struct {
    Name     string             `yaml:"name"`
    Channels []TrdlGroupChannel `yaml:"channels,omitempty"`
}

type TrdlGroupChannel struct {
    Name    string `yaml:"name"`
    Version string `yaml:"version"`
}

func ParseTrdlChannels(data []byte) (*TrdlChannels, error) {
    var res *TrdlChannels

    if err := yaml.Unmarshal(data, &res); err != nil {
        return nil, fmt.Errorf("error unmarshalling yaml: %w", err)
    }

    return res, nil
}