Giter Club home page Giter Club logo

dgoyaml's Introduction

dgoyaml Dgo YAML bi-directional serialization

This module provides YAML serialization/deserialization for Dgo using the gopkg.in/yaml.v3 module.

Using dgoyaml as a library

To use dgoyaml, first install the latest version of the library:

go get github.com/lyraproj/dgoyaml

Running the dgo CLI

The dgo CLI command can be used to get acquainted with dgo concepts. It will allow you to declare types and values in YAML files and then use the types to validate the values. You install the command under $GOPATH/bin with:

go install github.com/lyraproj/dgoyaml/cli/dgo

after that, you should be able to do:

dgo help

to get a description of avaliable sub commands and flags.

Example of usage:

Let's assume some kind of typed parameters in YAML that the user enters like this:

host: example.com
port: 22

The task is to create a user friendly description of a parameter, also in YAML, which can be used to validate the above parameters. Something like this:

host:
  type: string[1]
  name: sample/service_host
  required: true
port:
  type: 1..999
  name: sample/service_port

The value of each type is a dgo type. They limit the host parameter to a non empty string and the port parameter to an integer in the range 1-999. A special required entry is used to denote whether or not a parameter value must be present. The name entry is optional and provides a freeform text identifier.

Put the two above YAML examples in two separate files, params.yaml and params_spec.yaml. Then run the command:

dgo validate --verbose --input params.yaml --spec params_spec.yaml

The output should be:

Got input yaml with:
  host: example.com
  port: 22
Validating 'host' against definition string[1]
  'host' OK!
Validating 'port' against definition 1..999
  'port' OK!

For examples of how to use the library functions that Dgo provides to perform the above validation in, please take a look at parameter_test.go. The source of the validate command may also be of help.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.