cannot use phone (type string) as type int in assignment [duplicate]Convert string to integer type in Go?In Go, one type is coerced into another, can a method to determine the type of the receiver?Why can't I put the opening braces on the next line?Type conversion of string to intStruct type immtable“goapp build” works, but “appcfg.py update” just “can't find import”…?cannot use Context as type “handlerfunc” gin-gonicCan't make a slice of a column of a 2d array “cannot use Sudoku[0:9][0] (type [9]int) as type []int in assignment”Golang import struct and share over all apphow do i resolve cannot refer to unexported field or method models.Model.getDevices in golangwhy my code error (mssql: Violation of PRIMARY KEY constraint 'PK_SMSBlast2'. Cannot insert duplicate key in object 'dbo.SMSBlast2')?

Why does Mjolnir fall down in Age of Ultron but not in Endgame?

Alternatives to achieve certain output format

Popcorn is the only acceptable snack to consume while watching a movie

Is "cool" appropriate or offensive to use in IMs?

My employer faked my resume to acquire projects

Parallel fifths in the orchestra

Efficient Algorithm for the boundary of a set of tiles

Is it legal to have an abortion in another state or abroad?

Make 24 using exactly three 3s

Why did the person in charge of a principality not just declare themself king?

When the Torah was almost lost and one (or several) Rabbis saved it?

How to deal with a colleague who is being aggressive?

Need to understand my home electrical meter to see why bill is so high and/or if neighbor is on same meter

How to politely tell someone they did not hit "reply to all" in an email?

Count rotary dial pulses in a phone number (including letters)

Of strange atmospheres - the survivable but unbreathable

Can the product of any two aperiodic functions which are defined on the entire number line be periodic?

Does pair production happen even when the photon is around a neutron?

What is a Power on Reset IC?

I know that there is a preselected candidate for a position to be filled at my department. What should I do?

How to respond to upset student?

Is the field of q-series 'dead'?

Ingress filtering on edge routers and performance concerns

The art of clickbait captions



cannot use phone (type string) as type int in assignment [duplicate]


Convert string to integer type in Go?In Go, one type is coerced into another, can a method to determine the type of the receiver?Why can't I put the opening braces on the next line?Type conversion of string to intStruct type immtable“goapp build” works, but “appcfg.py update” just “can't find import”…?cannot use Context as type “handlerfunc” gin-gonicCan't make a slice of a column of a 2d array “cannot use Sudoku[0:9][0] (type [9]int) as type []int in assignment”Golang import struct and share over all apphow do i resolve cannot refer to unexported field or method models.Model.getDevices in golangwhy my code error (mssql: Violation of PRIMARY KEY constraint 'PK_SMSBlast2'. Cannot insert duplicate key in object 'dbo.SMSBlast2')?






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;








-4
















This question already has an answer here:



  • Convert string to integer type in Go?

    5 answers



I have an error "cannot use phone (type string) as type int in assignment",
how to fix this?



I use in github.com/gin-gonic/gin and github.com/jinzhu/gor



 package main

import (
"github.com/jinzhu/gorm"
"github.com/gin-gonic/gin"
)

type Employees struct
gorm.Model
Phone int


func (idb *InDB) CreateEmployees(c *gin.Context)
var (
em models.Employees
result gin.H
)

phone := c.PostForm("phone")
em.Phone = phone

result = gin.H
"result": em,

c.JSON(http.StatusOK, result)










share|improve this question















marked as duplicate by peterSO go
Users with the  go badge can single-handedly close go questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 24 at 3:17


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















  • A phone number is not an integer. Why are you declaring it as one? How is (555) 555-5555 an integer value? You can do math operations on an int. How do you do that with a phone number? How do you multiply a phone number by 2?

    – Ken White
    Mar 24 at 2:55


















-4
















This question already has an answer here:



  • Convert string to integer type in Go?

    5 answers



I have an error "cannot use phone (type string) as type int in assignment",
how to fix this?



I use in github.com/gin-gonic/gin and github.com/jinzhu/gor



 package main

import (
"github.com/jinzhu/gorm"
"github.com/gin-gonic/gin"
)

type Employees struct
gorm.Model
Phone int


func (idb *InDB) CreateEmployees(c *gin.Context)
var (
em models.Employees
result gin.H
)

phone := c.PostForm("phone")
em.Phone = phone

result = gin.H
"result": em,

c.JSON(http.StatusOK, result)










share|improve this question















marked as duplicate by peterSO go
Users with the  go badge can single-handedly close go questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 24 at 3:17


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.


















  • A phone number is not an integer. Why are you declaring it as one? How is (555) 555-5555 an integer value? You can do math operations on an int. How do you do that with a phone number? How do you multiply a phone number by 2?

    – Ken White
    Mar 24 at 2:55














-4












-4








-4









This question already has an answer here:



  • Convert string to integer type in Go?

    5 answers



I have an error "cannot use phone (type string) as type int in assignment",
how to fix this?



I use in github.com/gin-gonic/gin and github.com/jinzhu/gor



 package main

import (
"github.com/jinzhu/gorm"
"github.com/gin-gonic/gin"
)

type Employees struct
gorm.Model
Phone int


func (idb *InDB) CreateEmployees(c *gin.Context)
var (
em models.Employees
result gin.H
)

phone := c.PostForm("phone")
em.Phone = phone

result = gin.H
"result": em,

c.JSON(http.StatusOK, result)










share|improve this question

















This question already has an answer here:



  • Convert string to integer type in Go?

    5 answers



I have an error "cannot use phone (type string) as type int in assignment",
how to fix this?



I use in github.com/gin-gonic/gin and github.com/jinzhu/gor



 package main

import (
"github.com/jinzhu/gorm"
"github.com/gin-gonic/gin"
)

type Employees struct
gorm.Model
Phone int


func (idb *InDB) CreateEmployees(c *gin.Context)
var (
em models.Employees
result gin.H
)

phone := c.PostForm("phone")
em.Phone = phone

result = gin.H
"result": em,

c.JSON(http.StatusOK, result)





This question already has an answer here:



  • Convert string to integer type in Go?

    5 answers







go go-gorm gin






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Mar 29 at 9:07









robbieperry22

371220




371220










asked Mar 24 at 2:41









rsmnartsrsmnarts

714




714




marked as duplicate by peterSO go
Users with the  go badge can single-handedly close go questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 24 at 3:17


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.









marked as duplicate by peterSO go
Users with the  go badge can single-handedly close go questions as duplicates and reopen them as needed.

StackExchange.ready(function()
if (StackExchange.options.isMobile) return;

$('.dupe-hammer-message-hover:not(.hover-bound)').each(function()
var $hover = $(this).addClass('hover-bound'),
$msg = $hover.siblings('.dupe-hammer-message');

$hover.hover(
function()
$hover.showInfoMessage('',
messageElement: $msg.clone().show(),
transient: false,
position: my: 'bottom left', at: 'top center', offsetTop: -7 ,
dismissable: false,
relativeToBody: true
);
,
function()
StackExchange.helpers.removeMessages();

);
);
);
Mar 24 at 3:17


This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.














  • A phone number is not an integer. Why are you declaring it as one? How is (555) 555-5555 an integer value? You can do math operations on an int. How do you do that with a phone number? How do you multiply a phone number by 2?

    – Ken White
    Mar 24 at 2:55


















  • A phone number is not an integer. Why are you declaring it as one? How is (555) 555-5555 an integer value? You can do math operations on an int. How do you do that with a phone number? How do you multiply a phone number by 2?

    – Ken White
    Mar 24 at 2:55

















A phone number is not an integer. Why are you declaring it as one? How is (555) 555-5555 an integer value? You can do math operations on an int. How do you do that with a phone number? How do you multiply a phone number by 2?

– Ken White
Mar 24 at 2:55






A phone number is not an integer. Why are you declaring it as one? How is (555) 555-5555 an integer value? You can do math operations on an int. How do you do that with a phone number? How do you multiply a phone number by 2?

– Ken White
Mar 24 at 2:55













1 Answer
1






active

oldest

votes


















1














Value in PostForm are all strings. You should declare phone as string type, or convert the phone number from string to integer. Like strconv.Atoi or strconv.ParseInt



phone := c.PostForm("phone")
phoneNumber, _ := strconv.Atoi(phone)
em.Phone = phoneNumber





share|improve this answer































    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    1














    Value in PostForm are all strings. You should declare phone as string type, or convert the phone number from string to integer. Like strconv.Atoi or strconv.ParseInt



    phone := c.PostForm("phone")
    phoneNumber, _ := strconv.Atoi(phone)
    em.Phone = phoneNumber





    share|improve this answer





























      1














      Value in PostForm are all strings. You should declare phone as string type, or convert the phone number from string to integer. Like strconv.Atoi or strconv.ParseInt



      phone := c.PostForm("phone")
      phoneNumber, _ := strconv.Atoi(phone)
      em.Phone = phoneNumber





      share|improve this answer



























        1












        1








        1







        Value in PostForm are all strings. You should declare phone as string type, or convert the phone number from string to integer. Like strconv.Atoi or strconv.ParseInt



        phone := c.PostForm("phone")
        phoneNumber, _ := strconv.Atoi(phone)
        em.Phone = phoneNumber





        share|improve this answer















        Value in PostForm are all strings. You should declare phone as string type, or convert the phone number from string to integer. Like strconv.Atoi or strconv.ParseInt



        phone := c.PostForm("phone")
        phoneNumber, _ := strconv.Atoi(phone)
        em.Phone = phoneNumber






        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Mar 24 at 3:26

























        answered Mar 24 at 2:59









        HolaYangHolaYang

        33919




        33919















            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript