Skip to content

this is a simple remote config for golang. It supports yaml and json files. It also supports local Files, github repositories and web urls.

Notifications You must be signed in to change notification settings

divakarmanoj/go-remote-config

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

46 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

go-remote-config

go build and test codecov

this is a simple remote config for golang. It supports yaml and json files. It also supports local Files, github repositories and web urls.

Usage

FileRepository

package main

import (
	"context"
	"github.com/divakarmanoj/go-remote-config/client"
	"github.com/divakarmanoj/go-remote-config/source"
	"time"
)

func main() {
	repository := source.FileRepository{
		Path: "config.yaml",
		Name: "config",
	}
	ctx := context.Background()
	ConfigClient := client.NewClient(ctx, &repository, 10*time.Second)
	var name string
	err := ConfigClient.GetConfig("name", &name)
	if err != nil {
		return
	}
}

Web Repository

package main

import (
	"context"
	"github.com/divakarmanoj/go-remote-config/client"
	"github.com/divakarmanoj/go-remote-config/source"
	"net/url"
	"time"
)

func main() {
	urlParsed, err := url.Parse("https://raw.githubusercontent.com/divakarmanoj/go-remote-config/go-only/test.yaml")
	if err != nil {
		return
	}
	repository := source.WebRepository{
		URL:  urlParsed,
		Name: "config",
	}
	ctx := context.Background()
	ConfigClient := client.NewClient(ctx, &repository, 10*time.Second)
	var name string
	err = ConfigClient.GetConfig("name", &name)
	if err != nil {
		return
	}
	println(name)
}

Github Repository

package main

import (
	"context"
	"github.com/divakarmanoj/go-remote-config/client"
	"github.com/divakarmanoj/go-remote-config/source"
	"net/url"
	"time"
)

func main() {
	urlParsed, err := url.Parse("https://github.com/divakarmanoj/go-remote-config.git")
	if err != nil {
		return
	}
	repository := source.GitRepository{
		URL:    urlParsed,
		Path:   "test.yaml",
		Branch: "go-only",
	}
	ctx := context.Background()
	ConfigClient := client.NewClient(ctx, &repository, 10*time.Second)
	var name string
	err = ConfigClient.GetConfig("name", &name)
	if err != nil {
		return
	}
	println(name)
}

About

this is a simple remote config for golang. It supports yaml and json files. It also supports local Files, github repositories and web urls.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages