github.com/nya3jp/tast@v0.0.0-20230601000426-85c8e4d83a9b/src/go.chromium.org/tast/core/internal/command/ipc.go (about) 1 // Copyright 2019 The ChromiumOS Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 package command 6 7 // CopyFieldIfNonZero copies *src to *dst if *src does not contain the zero value. 8 // This is intended to be used when deprecating fields in structs used for IPC. 9 // src and dst must be of the same type; *bool, *string, and *[]string are supported. 10 // This function panics if passed any other types. 11 func CopyFieldIfNonZero(src, dst interface{}) { 12 switch s := src.(type) { 13 case *bool: 14 if *s { 15 *dst.(*bool) = *s 16 } 17 case *string: 18 if *s != "" { 19 *dst.(*string) = *s 20 } 21 case *[]string: 22 if *s != nil { 23 *dst.(*[]string) = *s 24 } 25 default: 26 panic("Unsupported deprecated field type") 27 } 28 }