github.com/drone/go-convert@v0.0.0-20240307072510-6bd371c65e61/convert/travis/yaml/enum_os.go (about) 1 // Copyright 2022 Harness, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 package yaml 16 17 // import "encoding/json" 18 19 // // List of operating systems. 20 // type OS int 21 22 // // OS enumeration. 23 // const ( 24 // OSNone OS = iota 25 // OSLinux 26 // OSWindows 27 // OSMacos 28 // ) 29 30 // // String returns the OS as a string. 31 // func (e OS) String() string { 32 // switch e { 33 // case OSLinux: 34 // return "linux" 35 // case OSWindows: 36 // return "windows" 37 // case OSMacos: 38 // return "osx" 39 // default: 40 // return "" 41 // } 42 // } 43 44 // // MarshalJSON marshals the type as a JSON string. 45 // func (e OS) MarshalJSON() ([]byte, error) { 46 // return json.Marshal(e.String()) 47 // } 48 49 // // UnmarshalJSON unmashals a quoted json string to the enum value. 50 // func (e *OS) UnmarshalJSON(b []byte) error { 51 // var v string 52 // json.Unmarshal(b, &v) 53 // switch v { 54 // case "linux": 55 // *e = OSLinux 56 // case "windows": 57 // *e = OSWindows 58 // case "macos", "mac", "osx": 59 // *e = OSMacos 60 // default: 61 // *e = OSNone 62 // } 63 // return nil 64 // } 65 66 // // UnmarshalJSON unmashals a quoted json string to the enum value. 67 // // UnmarshalYAML implements the unmarshal interface. 68 // func (e *OS) UnmarshalYAML(unmarshal func(interface{}) error) error { 69 // var v string 70 // unmarshal(v) 71 // switch v { 72 // case "linux": 73 // *e = OSLinux 74 // case "windows": 75 // *e = OSWindows 76 // case "macos", "mac", "osx": 77 // *e = OSMacos 78 // default: 79 // *e = OSNone 80 // } 81 // return nil 82 // }