github.com/Azareal/Gosora@v0.0.0-20210729070923-553e66b59003/tmplstub.go (about) 1 package main 2 3 import ( 4 //"reflect" 5 //"runtime" 6 //"unsafe" 7 "github.com/Azareal/Gosora/uutils" 8 ) 9 10 // TODO: Add a safe build mode for things like Google Appengine 11 12 var GetFrag = func(name string) [][]byte { 13 return nil 14 } 15 16 type WriteString interface { 17 WriteString(s string) (n int, err error) 18 } 19 20 var StringToBytes = uutils.StringToBytes 21 var BytesToString = uutils.BytesToString 22 var Nanotime = uutils.Nanotime 23 24 /* 25 func StringToBytes(s string) (bytes []byte) { 26 str := (*reflect.StringHeader)(unsafe.Pointer(&s)) 27 slice := (*reflect.SliceHeader)(unsafe.Pointer(&bytes)) 28 slice.Data = str.Data 29 slice.Len = str.Len 30 slice.Cap = str.Len 31 runtime.KeepAlive(&s) 32 return bytes 33 } 34 func BytesToString(bytes []byte) (s string) { 35 slice := (*reflect.SliceHeader)(unsafe.Pointer(&bytes)) 36 str := (*reflect.StringHeader)(unsafe.Pointer(&s)) 37 str.Data = slice.Data 38 str.Len = slice.Len 39 runtime.KeepAlive(&bytes) 40 return s 41 } 42 //go:noescape 43 //go:linkname nanotime runtime.nanotime 44 func nanotime() int64 45 func Nanotime() int64 { 46 return nanotime() 47 }*/