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

            How to preserve electronics (computers, tablets and phones) for hundreds of years Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern) The network's official Twitter account is up and running again. What content…How might modern humans leave a message for 50,000 years?How would an aquatic race develop computers?How do we make computers care for human life?Keeping supplies for 1000 yearsWhat will cell phones become in 100 years?What body armor protects against a laser?Could a society attain 1800s technology if limited to using copper and bronze?Electricity power (magic) and electronicsScavenging metal resources in post-apocalypse after 100 yearsWhy would precursors create devices that can survive and still work after hundreds of years?

            155 수학 과학 기타 둘러보기 메뉴eh추가해eh문서를 완성해

            Convert JSON to MapSimplest way to convert a string representing JSON array into Java array List of key value pairsHow to take String JSON values into HashMapConvert a JSON String to a HashMapCreating BSON object from JSON stringJSONObject - How to get a value ?Better Map ConstructorReading JSON from Url javaUpdate columns if input values are not null otherwise ignore and keep the existing values of column in databaseHow to store object represented as Json string into Couchbase Lite?Go JSON into MapHow do I efficiently iterate over each entry in a Java Map?Sort a Map<Key, Value> by valuesHow to round a number to n decimal places in JavaCan comments be used in JSON?How do I read / convert an InputStream into a String in Java?How can I pretty-print JSON in a shell script?What is the correct JSON content type?How can I deserialize JSON to a simple Dictionary<string,string> in ASP.NET?Why does Google prepend while(1); to their JSON responses?Parse JSON in JavaScript?