8 , 1 6 , 3 2 , 6 4 } f l o a t { 3 2 , 6 4 } c o m p l e x { 6 4 , 1 2 8 } b o o l b y t e r u n e "Code point" in Unicode (item represented by a single value). s t r i n g
type definition specifies a length and an element type. s l i c e s A slice is a data structure describing a contiguous section of an array stored separately from the slice variable itself. A slice is not an array. A slice describes a piece of an array. m a p s Key/value storage.
o i n t e r s f u n c t i o n s i n t e r f a c e s t y p e S h o p a s t r u c t { e m p l o y e e s i n t } f u n c m a i n ( ) { s : = S h o p a { e m p l o y e e s : 2 , } f m t . P r i n t l n ( s . e m p l o y e e s ) } Run
imagined to be a pipe or a conveyer belt of a defined size and capacity. On one side one can place an item onto this imaginary conveyer belt and on the other side one can take it."
E r r o r = e r r o r s . N e w ( " I s t h i s a n e x c e p t i o n ? " ) f u n c b r e a k S o m e t h i n g ( ) e r r o r { r e t u r n N a m e d E r r o r } f u n c m a i n ( ) { e r r : = b r e a k S o m e t h i n g ( ) s w i t c h e r r { c a s e N a m e d E r r o r : l o g . P r i n t l n ( " F a i l e d a s e x p e c t e d " ) d e f a u l t : l o g . P a n i c ( " I d i d n ' t e x p e c t t h i s ! " ) } i f e r r : = b r e a k S o m e t h i n g ( ) ; e r r = = N a m e d E r r o r { l o g . P r i n t l n ( " T h i s f a i l e d a s e x p e c t e d a s w e l l ! " ) } } Run
n s t r u c t { N a m e s t r i n g } f u n c m a i n ( ) { p a y l o a d : = [ ] b y t e ( ` [ { " n a m e " : " A l e x " } , { " n a m e " : " N i c o l a " } ] ` ) v a r p e o p l e [ ] P e r s o n i f e r r : = j s o n . U n m a r s h a l ( p a y l o a d , & p e o p l e ) ; e r r ! = n i l { l o g . P a n i c ( e r r ) / / D o n ' t d o t h i s a t h o m e } f o r _ , p : = r a n g e p e o p l e { f m t . P r i n t l n ( p . N a m e ) } } Run
u t ( w h a t e v e r i n t e r f a c e { } ) { s w i t c h v : = w h a t e v e r . ( t y p e ) { c a s e s t r i n g : f m t . P r i n t l n ( " A S t r i n g : " , v ) c a s e i n t : f m t . P r i n t l n ( " S o m e i n t : " , v ) d e f a u l t : f m t . P r i n t l n ( " I d o n ' t k n o w w h a t t y p e i s t h i s o n e : " , v ) } } f u n c m a i n ( ) { o u t p u t ( " t h i s i s s o m e t e x t " ) o u t p u t ( 1 ) o u t p u t ( 1 . 1 ) } Run
h o p e r i n t e r f a c e { L i k e s F a s h i o n ( ) b o o l } t y p e ( C a r S h o p e r s t r u c t { } S h o e S h o p e r s t r u c t { } ) f u n c ( s C a r S h o p e r ) L i k e s F a s h i o n ( ) b o o l { r e t u r n f a l s e } f u n c ( s S h o e S h o p e r ) L i k e s F a s h i o n ( ) b o o l { r e t u r n t r u e } f u n c I s P o s s i b l e S h o p a C l i e n t ( s S h o p e r ) b o o l { r e t u r n s . L i k e s F a s h i o n ( ) } f u n c m a i n ( ) { f m t . P r i n t l n ( I s P o s s i b l e S h o p a C l i e n t ( C a r S h o p e r { } ) , I s P o s s i b l e S h o p a C l i e n t ( S h o e S h o p e r { } ) ) } Run
( i i n t , d o n e c h a n b o o l ) { t i m e . S l e e p ( t i m e . D u r a t i o n ( r a n d . I n t n ( 3 ) ) * t i m e . S e c o n d ) f m t . P r i n t l n ( i ) d o n e < - t r u e } f u n c m a i n ( ) { d o n e : = m a k e ( c h a n b o o l , 1 ) f o r i : = 0 ; i < 1 0 ; i + + { g o d o i t ( i , d o n e ) } f o r i : = 0 ; i < 1 0 ; i + + { < - d o n e } } Run
i n ( ) { v a r w g s y n c . W a i t G r o u p f o r i : = 0 ; i < 1 0 ; i + + { w g . A d d ( 1 ) g o f u n c ( i i n t ) { f m t . P r i n t l n ( i ) w g . D o n e ( ) } ( i ) } w g . W a i t ( ) } Run
q u e u e c h a n < - P e r s o n , w g * s y n c . W a i t G r o u p ) { d e f e r c l o s e ( q u e u e ) d e f e r w g . D o n e ( ) f o r _ , n a m e : = r a n g e [ ] s t r i n g { " A l e x " , " N i c o l a " , " G e o r g e " , " A n t h o n y " , " S a m " } { q u e u e < - P e r s o n { n a m e } t i m e . S l e e p ( t i m e . D u r a t i o n ( r a n d . I n t n ( 1 0 0 0 ) ) * t i m e . M i l l i s e c o n d ) } } f u n c v i s i t ( q u e u e < - c h a n P e r s o n , w g * s y n c . W a i t G r o u p ) { d e f e r w g . D o n e ( ) f o r p : = r a n g e q u e u e { f m t . P r i n t l n ( p . N a m e , " i s v i s i t i n g " ) } } f u n c m a i n ( ) { q u e u e : = m a k e ( c h a n P e r s o n , 2 ) / / . . . Run
n t e r i n t p o r t = 9 0 0 0 ) f u n c c o u n t ( w h t t p . R e s p o n s e W r i t e r , r * h t t p . R e q u e s t ) { c o u n t e r + + } f u n c s t a t s ( w h t t p . R e s p o n s e W r i t e r , r * h t t p . R e q u e s t ) { w . W r i t e ( [ ] b y t e ( f m t . S p r i n t f ( " V i s i t s : % d " , c o u n t e r ) ) ) } f u n c m a i n ( ) { / / h t t p . H a n d l e F u n c ( " / f a v i c o n . i c o " , f u n c ( _ h t t p . R e s p o n s e W r i t e r , _ * h t t p . R e q u e s t ) { } ) h t t p . H a n d l e F u n c ( " / " , c o u n t ) h t t p . H a n d l e F u n c ( " / s t a t s " , s t a t s ) l o g . P r i n t l n ( " L i s t e n i n g a t p o r t " , p o r t ) l o g . P a n i c ( h t t p . L i s t e n A n d S e r v e ( f m t . S p r i n t f ( " : % d " , p o r t ) , n i l ) ) } Run