realm

command module
v0.0.17 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 3, 2021 License: Apache-2.0 Imports: 1 Imported by: 0

README

realm

release

go install github.com/steviebps/realm

starter configs

a basic chamber file

wget -O $HOME/.realm/masterChamber.json https://raw.githubusercontent.com/steviebps/realm/master/configs/masterChamber.json

example commands

build

realm build -o /path/to/your/directory

with forced directory creation

realm build -o /path/to/your/directory --force

Pipe into an archive:

realm build | tar zcf realm.tar.gz -T -

print
Pretty prints your global chamber to stdout:

realm print -p

Print your global chamber to file:

realm print -o /path/to/your/file.json

example code snippets

import (
	"fmt"
	"log"
	"net/http"

	realm "github.com/steviebps/realm/pkg"
)


func main() {
	// because realm configurations contain overrides based on the version of your application, specify it here
	realm.SetVersion("v1.0.0")

  	// tell realm where to look for realm configuration
	if err := realm.AddConfigPath("./"); err != nil {
		log.Fatal(err)
	}

  	// tell realm what file name it should look for in the specified paths
	if err := realm.SetConfigName("chambers.json"); err != nil {
		log.Fatal(err)
	}

 	// look for and read in the realm configuration
  	// passing "true" will tell realm to watch the file for changes
	if err := realm.ReadInConfig(true); err != nil {
		log.Fatal(err)
	}

  	// return a float64 value from the config and specify a default value if it does not exist
	port, _ := realm.Float64Value("port", 3000)
  
	mux := http.NewServeMux()
	mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
    		// retrieve a string value from your realm config and specify a default value if it does not exist
		message, _ := realm.StringValue("message", "DEFAULT")
		w.Write([]byte(message))
	})
  
	log.Println("Listening on :", port)
	err := http.ListenAndServe(fmt.Sprintf(":%d", int(port)), mux)
	if err != nil {
		log.Fatal(err)
	}
}

Documentation

Overview

Copyright © 2020

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

Directories

Path Synopsis
examples
go command
internal

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL