func (pg *PostgreSQL) CreatePort(projectName string, ip string, port models.Port) error {
	pgp := pgPort{}
	pgp.FromModel(port)
	err := pg.createPort(projectName, ip, pgp)
	if err != nil {
		return err
	}
	return nil
}
CreatePort is the public wrapper to create a new port in the database.
package postgresql
import (
	"errors"
	"github.com/netm4ul/netm4ul/core/events"
	"github.com/jinzhu/gorm"
	"github.com/netm4ul/netm4ul/core/database/models"
	log "github.com/sirupsen/logrus"
)
func (pg *PostgreSQL) createOrUpdatePort(projectName string, ip string, port pgPort) error {
	log.Debugf("createOrUpdate Port : %+v", port)
	var foundPort pgPort
	res := pg.db.Raw(selectPortsByProjectNameAndIP, projectName, ip).Scan(&foundPort)
	if gorm.IsRecordNotFoundError(res.Error) {
		return pg.createPort(projectName, ip, port)
	}
	if res.Error != nil {
		return errors.New("Could not select port : " + res.Error.Error())
	}
	err := pg.updatePort(projectName, ip, port)
	if err != nil {
		return errors.New("Could not update port : " + err.Error())
	}
	return nil
}
func (pg *PostgreSQL) CreateOrUpdatePort(projectName string, ip string, port models.Port) error {
	pgp := pgPort{}
	pgp.FromModel(port)
	err := pg.createOrUpdatePort(projectName, ip, pgp)
	if err != nil {
		return err
	}
	return nil
}
func (pg *PostgreSQL) createPort(projectName string, ip string, port pgPort) error {
	res := pg.db.Debug().Create(&port)
	if res.Error != nil {
		return errors.New("Could not insert ip : " + res.Error.Error())
	}
	events.NewEventPort(port.ToModel())
	return nil
}