Soy

Oscar Luis Sánchez Jara

Dev-Lusaja

Hola!!!

Acerca de mi:

Sígueme en:

/dev_lusaja

/dev-lusaja

Conociendo

GOLANG

¿Qué es GO?

Es un lenguaje de programación de código abierto que permite construir de manera sencilla un software que sea simple, seguro y confiable.

Historia . . .

Fue desarrollado por los ingenieros de Google Robert Griesemer, Rob Pike, y Ken Thompson en el 2007 como alternativa al C++.

El lenguaje fue liberado en noviembre del 2009 y ahora se utiliza en algunos de los sistemas de producción de Google.

 

Características

  • Combina una sintaxis parecida a C con las características y la facilidad de los lenguajes dinámicos como Python.
  • Tipado estático.
  • Compilado.
  • Concurrencia.
  • Orientado a Objetos. (Interfaces)

Algunos grandes que utilizan GO

¿Porqué utilizar GO?

  • No depende de ninguna versión de sistema operativo.
  • Permite construir aplicaciones web de manera simple.
  • Tiene un sistema recolector de basura que ayuda a optimizar la memoria RAM.
  • Es open source.
  • Cuenta con una numerosa comunidad a nivel mundial.
  • Su compilador ayuda a limpiar el código fuente.

Primeros

pasos
 

Mi experiencia instalando GO

Instalador:

Configurar variables de entorno:

  • GOPATH

 

 

  • SISTEM PATH
    $ mkdir $HOME/go-projects
    $ export GOPATH=$HOME/go-projects
    $ export PATH=$PATH:$GOPATH/bin

Espacio de trabajo

   
     go-projects/                         
            bin/
                hola                         # comando ejecutable    
            pkg/
                linux_amd64/
                    github.com/golang/example/
                        example.a            # paquetes externos
            src/
            	hola/
            	    hola.go                  # código fuente

$GOPATH

Estructura del código


    package main  //nombre del paquete
    
    import (
    
        //paquetes importados
    )
    
    func init() {
    
        //función de inicialización
    }
    
    func main() {
    
        //función principal del programa
    
    }

Especificaciones del lenguaje

Tipos de datos

    Tipo Boolean 
    Tipo Numeric 
        	uint8       the set of all unsigned  8-bit integers (0 to 255)
        	uint16      the set of all unsigned 16-bit integers (0 to 65535)
        	uint32      the set of all unsigned 32-bit integers (0 to 4294967295)
        	uint64      the set of all unsigned 64-bit integers (0 to 18446744073709551615)
        	int8        the set of all signed  8-bit integers (-128 to 127)
        	int16       the set of all signed 16-bit integers (-32768 to 32767)
        	int32       the set of all signed 32-bit integers (-2147483648 to 2147483647)
        	int64       the set of all signed 64-bit integers ( +- 9223372036854775808)
        	float32     the set of all IEEE-754 32-bit floating-point numbers
        	byte        alias for uint8
        	rune        alias for int32
    Tipo String 
    Tipo Array 
    Tipo Slice 
    Tipo Struct 
    Tipo Pointer 
    Tipo Function 
    Tipo Interface 
    Tipo Map 
    Tipo Channel

Variables


    var (
    	nombre     string
    	edad       int
    )
    var nombre     string
    var edad       int
    
    var nombre = "Oscar"
    
    func main(){
        nombre, edad := "Dev-lusaja", 25
    }

Constantes


 //character, string, boolean or numeric
    const (
    	nombre     string
    	edad       int
    )
    const nombre     string
    const edad       int
   
    
    func main(){
        const nombre = "Dev-lusaja"
    }

Funciones


    package main
    
    // importamos la librería fmt para hacer impresiones en pantalla.
    import "fmt"
    
    // recibimos 2 valores enteros y devolvemos un valor entero.
    func suma(v1, v2 int) int {
    	res := v1 + v2
    	return res
    }
    
    // función principal del programa.
    func main() {
    	res := suma(1,1)
    	fmt.Println(res)
    }

//Resultado
  //2

Estructuras


    package main
    
    import "fmt"
    
    //Definimos un tipo de estructura llamada Usuario
    type Usuario struct{
    	nombre string
    	edad int
    }
    
    func main() {
        //Creamos una nueva estructura de tipo Usuario
    	usu := Usuario{"Dev-lusaja", 25}
    	fmt.Println(usu)
    }

//Resultado
  //{Dev-lusaja 25}

Interfaces

    package main
    
    import "fmt"
    
    type Shaper interface {
       Area() int
    }
    type Rectangle struct {
       length, width int
    }
    func (r Rectangle) Area() int {
       return r.length * r.width
    }
    func main() {
       r := Rectangle{length:5, width:3}
       fmt.Println("Rectangle r details are: ", r)  
       fmt.Println("Rectangle r's area is: ", r.Area())  
    
       s := Shaper(r)
       fmt.Println("Area of the Shape r is: ", s.Area())    
    }

Punteros


    package main
    
    import "fmt"
    
    func Valor(val int){
    	val = 0
    }
    
    func Valor2(val *int){
    	*val = 0
    }
    
    func main() {
    	v := 1                                            //Resultado
       	fmt.Println("Valor inicial:", v)                    //Valor inicial: 1
    	value(v)                                            //Usando func Valor: 1
    	fmt.Println("Usando func Valor:", v)                //Usando func Valor2: 0
    	value2(&v)
    	fmt.Println("Usando func Valor2:", v)
    }

Recursos

  • www.golangbootcamp.com/book/_single-page
  • golang.org/doc/
  • gobyexample.com/

Golang

By Oscar Luis Sánchez Jara

Golang

Charla Introducción a GO para el Ica Tech Day en la Universidad Nacional San Luis Gonzaga (UNICA). Ica - Perú

  • 893