Skip to content

Commit c4817d2

Browse files
committed
first commit
0 parents  commit c4817d2

File tree

4 files changed

+127
-0
lines changed

4 files changed

+127
-0
lines changed

apis.go

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
package main
2+
3+
/**
4+
* Instrucciones
5+
* $ export GOPATH=$HOME/go
6+
* $ go get -u github.com/labstack/echo
7+
* $ go get -u github.com/labstack/echo/middleware
8+
* $ go get -u github.com/jinzhu/gorm
9+
* $ go get -u github.com/go-sql-driver/mysql
10+
*/
11+
import (
12+
"log"
13+
"github.com/labstack/echo"
14+
"github.com/labstack/echo/middleware"
15+
"github.com/jinzhu/gorm"
16+
_ "github.com/go-sql-driver/mysql"
17+
18+
"./models"
19+
)
20+
21+
22+
func main() {
23+
i := Impl{}
24+
i.InitDB()
25+
// i.InitSchema() // Enable AutoMigrate
26+
27+
// Echo instance
28+
e := echo.New()
29+
30+
// Middleware
31+
e.Use(middleware.Gzip())
32+
e.Use(middleware.Logger())
33+
e.Use(middleware.Recover())
34+
35+
// Route => handler
36+
e.GET("/", func(c echo.Context) error {
37+
var pedimentos []models.Pedimentos
38+
err := i.DB.Find(&pedimentos).Error
39+
40+
if err != nil {
41+
log.Fatalf("Got error when query, the error is '%v'", err)
42+
return c.JSON(404, err)
43+
}
44+
45+
return c.JSON(200, pedimentos)
46+
})
47+
// Start server
48+
e.Logger.Fatal(e.Start(":8001"))
49+
}
50+
51+
func (i *Impl) InitDB() {
52+
var err error
53+
i.DB, err = gorm.Open("mysql", "USER:PASSWORD@tcp(IP_SERVER:3306)/DATABASE?charset=utf8&parseTime=True")
54+
if err != nil {
55+
log.Fatalf("Got error when connect database, the error is '%v'", err)
56+
}
57+
58+
i.DB.LogMode(true)
59+
i.DB.SingularTable(true)
60+
}
61+
62+
func (i *Impl) InitSchema() {
63+
i.DB.AutoMigrate(&models.Pedimentos{}, &models.Departamento{})
64+
}
65+
66+
type Impl struct {
67+
DB *gorm.DB
68+
}

models/departamento.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package models
2+
3+
type Departamento struct {
4+
ID int `json:"id" gorm:"column:dep_id;primary_key;AUTO_INCREMENT"`
5+
Nombre string `json:"nombre" gorm:"column:dep_nombre;size:85;not null"`
6+
Abreviado string `json:"abreviado" gorm:"column:dep_abreviado;size:15;not null"`
7+
Email string `json:"email" gorm:"column:dep_email;size:128;not null"`
8+
Activo bool `json:"activo" gorm:"type:tinyint(1);column:dep_activo"`
9+
ReparticionCliente bool `json:"reparticion" gorm:"type:tinyint(1);column:dep_reparticion_cliente"`
10+
}

models/pedimentos.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package models
2+
3+
import "time"
4+
5+
type Pedimentos struct {
6+
PedimentoID int `json:"pedimentoid" gorm:"column:pedimentoid;primary_key"`
7+
RemesaID int `json:"remesaid" gorm:"column:remesaid;"`
8+
ClienteID int `json:"clienteid" gorm:"column:clienteid;not null"`
9+
Cliente string `json:"cliente" gorm:"column:cliente;size:64"`
10+
CruceID int `json:"cruceid" gorm:"column:cruceid"`
11+
Aduana int `json:"aduana" gorm:"column:aduana"`
12+
Patente int `json:"patente" gorm:"column:patente"`
13+
Pedimento string `json:"pedimento" gorm:"column:pedimento;size:64"`
14+
NumPedimento string `json:"num_pedimento" gorm:"column:num_pedimento;size:64"`
15+
Remesa int `json:"remesa" gorm:"column:remesa"`
16+
Tipo string `json:"tipo" gorm:"column:tipo;size:255"`
17+
Partidas int `json:"partidas" gorm:"column:partidas"`
18+
Placas string `json:"placas" gorm:"column:placas;size:64"`
19+
Factura string `json:"factura" gorm:"column:factura;size:64"`
20+
Clase string `json:"clase" gorm:"column:clase;size:64"`
21+
Clave string `json:"clave" gorm:"column:clave;size:64"`
22+
Status string `json:"status" gorm:"column:status;size:64"`
23+
Costos bool `json:"costos" gorm:"column:costos;type:tinyint(1);"`
24+
Checklist bool `json:"checklist" gorm:"column:checklist;type:tinyint(1);"`
25+
Cobros bool `json:"cobros" gorm:"column:cobros;type:tinyint(1);"`
26+
PedimentoCol string `json:"pedimentocol" gorm:"column:pedimentocol;size:64"`
27+
Ubicacion string `json:"ubicacion" gorm:"column:ubicacion;size:124"`
28+
Observaciones string `json:"observaciones" gorm:"column:observaciones;size:500"`
29+
Autorizado bool `json:"autorizado" gorm:"column:autorizado;type:tinyint(1);"`
30+
CodigoAutorizacion string `json:"codigo_autorizacion" gorm:"column:codigo_autorizacion;size:128"`
31+
Archivado bool `json:"archivado" gorm:"column:archivado;type:tinyint(1);"`
32+
SoiaRemesa string `json:"soiaremesa" gorm:"column:soiaremesa;size:45"`
33+
FechaApertura time.Time `json:"fecha_apertura" gorm:"column:fecha_apertura;type:date"`
34+
FechaPedimento time.Time `json:"fecha_pedimento" gorm:"column:fecha_pedimento;type:date"`
35+
FechaCierre time.Time `json:"fecha_cierre" gorm:"column:fecha_cierre;type:date"`
36+
FechaDocumentacion time.Time `json:"fecha_documentacion" gorm:"column:fecha_documentacion;type:timestamp;not null"`
37+
fecha_checklist time.Time `json:"fecha_checklist" gorm:"column:fecha_checklist;type:datetime"`
38+
fecha_autorizacion time.Time `json:"fecha_autorizacion" gorm:"column:fecha_autorizacion;type:datetime"`
39+
}

models/result.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package models
2+
3+
type Result struct {
4+
Field string
5+
Type string
6+
Null string
7+
Key string
8+
Default string
9+
Extra string
10+
}

0 commit comments

Comments
 (0)