Skip to content
This repository was archived by the owner on Jul 12, 2025. It is now read-only.
This repository was archived by the owner on Jul 12, 2025. It is now read-only.

cannot use net.ParseIP(c.IP()) (type net.IP) as type pgtype.Inet in field value #180

@encryptblockr

Description

@encryptblockr

here is my model

import (
    "github.com/jackc/pgtype"
)

...
ClientIp     pgtype.Inet `json:"client_ip" gorm:"type:inet;not null"`
...

I am trying to parse the ip address which is in string format to type pgtype.Inet in postgresql database
like this when inserting into the database

import (
    "net"
)

...
ClientIp:     net.ParseIP(c.IP()),
...

we are told to parse the ip using net package but this is error from that

cannot use net.ParseIP(c.IP()) (type net.IP) as type pgtype.Inet in field value

I have also tried using net package for the model

import (
    "net"
)

...
ClientIp     net.IP `json:"client_ip" gorm:"type:inet;not null"`
...

but kept getting this error

sql: Scan error on column index 16, name "client_ip": unsupported Scan, storing driver.Value type string into type *net.IP

so how do we store inet values inside postgresql using GORM?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions