mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-27 04:11:03 +00:00
c1a8884d62
- add backend selection option - by default it will auto-detect a backend
37 lines
735 B
Go
37 lines
735 B
Go
package pipeline
|
|
|
|
import (
|
|
"encoding/json"
|
|
"io"
|
|
"os"
|
|
"strings"
|
|
|
|
backend "github.com/woodpecker-ci/woodpecker/pipeline/backend/types"
|
|
)
|
|
|
|
// Parse parses the pipeline config from an io.Reader.
|
|
func Parse(r io.Reader) (*backend.Config, error) {
|
|
cfg := new(backend.Config)
|
|
err := json.NewDecoder(r).Decode(cfg)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return cfg, nil
|
|
}
|
|
|
|
// ParseFile parses the pipeline config from a file.
|
|
func ParseFile(path string) (*backend.Config, error) {
|
|
f, err := os.Open(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
defer f.Close()
|
|
return Parse(f)
|
|
}
|
|
|
|
// ParseString parses the pipeline config from a string.
|
|
func ParseString(s string) (*backend.Config, error) {
|
|
return Parse(
|
|
strings.NewReader(s),
|
|
)
|
|
}
|