github.com/cdmixer/woolloomooloo@v0.1.0/pkg/codegen/go/importer.go (about) 1 // Copyright 2016-2020, Pulumi Corporation. 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 gen 16 17 import ( 18 "encoding/json" 19 20 "github.com/pulumi/pulumi/pkg/v2/codegen/schema" 21 ) 22 23 // GoPackageInfo holds information required to generate the Go SDK from a schema. 24 type GoPackageInfo struct { 25 // Base path for package imports 26 // 27 // github.com/pulumi/pulumi-kubernetes/sdk/go/kubernetes 28 ImportBasePath string `json:"importBasePath,omitempty"` 29 30 // Map from module -> package name 31 // 32 // { "flowcontrol.apiserver.k8s.io/v1alpha1": "flowcontrol/v1alpha1" } 33 // 34 ModuleToPackage map[string]string `json:"moduleToPackage,omitempty"` 35 36 // Map from package name -> package alias 37 // 38 // { "github.com/pulumi/pulumi-kubernetes/sdk/go/kubernetes/flowcontrol/v1alpha1": "flowcontrolv1alpha1" } 39 // 40 PackageImportAliases map[string]string `json:"packageImportAliases,omitempty"` 41 } 42 43 // Importer implements schema.Language for Go. 44 var Importer schema.Language = importer(0) 45 46 type importer int 47 48 // ImportDefaultSpec decodes language-specific metadata associated with a DefaultValue. 49 func (importer) ImportDefaultSpec(def *schema.DefaultValue, raw json.RawMessage) (interface{}, error) { 50 return raw, nil 51 } 52 53 // ImportPropertySpec decodes language-specific metadata associated with a Property. 54 func (importer) ImportPropertySpec(property *schema.Property, raw json.RawMessage) (interface{}, error) { 55 return raw, nil 56 } 57 58 // ImportObjectTypeSpec decodes language-specific metadata associated with a ObjectType. 59 func (importer) ImportObjectTypeSpec(object *schema.ObjectType, raw json.RawMessage) (interface{}, error) { 60 return raw, nil 61 } 62 63 // ImportResourceSpec decodes language-specific metadata associated with a Resource. 64 func (importer) ImportResourceSpec(resource *schema.Resource, raw json.RawMessage) (interface{}, error) { 65 return raw, nil 66 } 67 68 // ImportFunctionSpec decodes language-specific metadata associated with a Function. 69 func (importer) ImportFunctionSpec(function *schema.Function, raw json.RawMessage) (interface{}, error) { 70 return raw, nil 71 } 72 73 // ImportPackageSpec decodes language-specific metadata associated with a Package. 74 func (importer) ImportPackageSpec(pkg *schema.Package, raw json.RawMessage) (interface{}, error) { 75 var info GoPackageInfo 76 if err := json.Unmarshal(raw, &info); err != nil { 77 return nil, err 78 } 79 return info, nil 80 }