cant convert String to *net.TCPlistener typeHow to efficiently concatenate strings in Go?Convert string to integer type in Go?How do you write multiline strings in Go?How to convert an int value to string in Go?Type converting slices of interfaces in GoHow to convert a zero-terminated byte array to string?Type conversion of string to intGO: Type assertion from listWhy does putting a pointer in an interface in Go cause reflect to lose the name of the type?Use reflect for set value of interface type
How did Arya manage the sneak attack?
Reverse the word in a string with the same order in javascript
Is it possible to Ready a spell to be cast just before the start of your next turn by having the trigger be an ally's attack?
Please, smoke with good manners
Do I have an "anti-research" personality?
Why does nature favour the Laplacian?
Python "triplet" dictionary?
Single Colour Mastermind Problem
Volunteering in England
Subtleties of choosing the sequence of tenses in Russian
Sci-fi novel series with instant travel between planets through gates. A river runs through the gates
Build a trail cart
Does jamais mean always or never in this context?
Is GOCE a satellite or aircraft?
How does a Swashbuckler rogue "fight with two weapons while safely darting away"?
Stark VS Thanos
Why “le” behind?
How can Republicans who favour free markets, consistently express anger when they don't like the outcome of that choice?
What is the difference between `a[bc]d` (brackets) and `ab,cd` (braces)?
When to use 1/Ka vs Kb
Pulling the rope with one hand is as heavy as with two hands?
Why does processed meat contain preservatives, while canned fish needs not?
Pressure to defend the relevance of one's area of mathematics
Modify locally tikzset
cant convert String to *net.TCPlistener type
How to efficiently concatenate strings in Go?Convert string to integer type in Go?How do you write multiline strings in Go?How to convert an int value to string in Go?Type converting slices of interfaces in GoHow to convert a zero-terminated byte array to string?Type conversion of string to intGO: Type assertion from listWhy does putting a pointer in an interface in Go cause reflect to lose the name of the type?Use reflect for set value of interface type
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
i want to put string in net.Listener but i got error :
./server.go:26:23: cannot use mainServer (type interface ) as type string in argument to net.Listen: need type assertion
./server.go:27:28: cannot use gpServer (type interface ) as type string in argument to net.Listen: need type assertion
its my code :
viper.SetConfigFile("config.json")
viper.AddConfigPath(".")
viper.SetConfigName("config")
viper.ReadInConfig()
fmt.Printf("Using config: %sn", viper.ConfigFileUsed())
mainServer := viper.Get("mainServer.port")
gpServer := viper.Get("gpServer.port")
fmt.Println(mainServer,gpServer)
fmt.Println("started main server")
ln, _ := net.Listen("tcp", mainServer)
gp_conn, _ := net.Listen("tcp", gpServer)
its my config.json :
"mainServer":
"host": "",
"port": ":2323",
"enabled": true
,
"gpServer":
"host": "",
"port": ":3232",
"enabled": true
}
can some one explain me how i can convert string to net.TCPListener Type ?
tnx
go
add a comment |
i want to put string in net.Listener but i got error :
./server.go:26:23: cannot use mainServer (type interface ) as type string in argument to net.Listen: need type assertion
./server.go:27:28: cannot use gpServer (type interface ) as type string in argument to net.Listen: need type assertion
its my code :
viper.SetConfigFile("config.json")
viper.AddConfigPath(".")
viper.SetConfigName("config")
viper.ReadInConfig()
fmt.Printf("Using config: %sn", viper.ConfigFileUsed())
mainServer := viper.Get("mainServer.port")
gpServer := viper.Get("gpServer.port")
fmt.Println(mainServer,gpServer)
fmt.Println("started main server")
ln, _ := net.Listen("tcp", mainServer)
gp_conn, _ := net.Listen("tcp", gpServer)
its my config.json :
"mainServer":
"host": "",
"port": ":2323",
"enabled": true
,
"gpServer":
"host": "",
"port": ":3232",
"enabled": true
}
can some one explain me how i can convert string to net.TCPListener Type ?
tnx
go
It says right in the error:need type assertion
. Also check the docs, because the package you're using probably has a convenience method to do this for you.
– JimB
Mar 22 at 19:37
godoc.org/github.com/spf13/viper#GetString
– Mad Wombat
Mar 22 at 19:53
Tnx "mad Wombat" ... My problem has been resolved ..
– MahdiNajafi
Mar 22 at 20:05
add a comment |
i want to put string in net.Listener but i got error :
./server.go:26:23: cannot use mainServer (type interface ) as type string in argument to net.Listen: need type assertion
./server.go:27:28: cannot use gpServer (type interface ) as type string in argument to net.Listen: need type assertion
its my code :
viper.SetConfigFile("config.json")
viper.AddConfigPath(".")
viper.SetConfigName("config")
viper.ReadInConfig()
fmt.Printf("Using config: %sn", viper.ConfigFileUsed())
mainServer := viper.Get("mainServer.port")
gpServer := viper.Get("gpServer.port")
fmt.Println(mainServer,gpServer)
fmt.Println("started main server")
ln, _ := net.Listen("tcp", mainServer)
gp_conn, _ := net.Listen("tcp", gpServer)
its my config.json :
"mainServer":
"host": "",
"port": ":2323",
"enabled": true
,
"gpServer":
"host": "",
"port": ":3232",
"enabled": true
}
can some one explain me how i can convert string to net.TCPListener Type ?
tnx
go
i want to put string in net.Listener but i got error :
./server.go:26:23: cannot use mainServer (type interface ) as type string in argument to net.Listen: need type assertion
./server.go:27:28: cannot use gpServer (type interface ) as type string in argument to net.Listen: need type assertion
its my code :
viper.SetConfigFile("config.json")
viper.AddConfigPath(".")
viper.SetConfigName("config")
viper.ReadInConfig()
fmt.Printf("Using config: %sn", viper.ConfigFileUsed())
mainServer := viper.Get("mainServer.port")
gpServer := viper.Get("gpServer.port")
fmt.Println(mainServer,gpServer)
fmt.Println("started main server")
ln, _ := net.Listen("tcp", mainServer)
gp_conn, _ := net.Listen("tcp", gpServer)
its my config.json :
"mainServer":
"host": "",
"port": ":2323",
"enabled": true
,
"gpServer":
"host": "",
"port": ":3232",
"enabled": true
}
can some one explain me how i can convert string to net.TCPListener Type ?
tnx
go
go
asked Mar 22 at 19:13
MahdiNajafiMahdiNajafi
11
11
It says right in the error:need type assertion
. Also check the docs, because the package you're using probably has a convenience method to do this for you.
– JimB
Mar 22 at 19:37
godoc.org/github.com/spf13/viper#GetString
– Mad Wombat
Mar 22 at 19:53
Tnx "mad Wombat" ... My problem has been resolved ..
– MahdiNajafi
Mar 22 at 20:05
add a comment |
It says right in the error:need type assertion
. Also check the docs, because the package you're using probably has a convenience method to do this for you.
– JimB
Mar 22 at 19:37
godoc.org/github.com/spf13/viper#GetString
– Mad Wombat
Mar 22 at 19:53
Tnx "mad Wombat" ... My problem has been resolved ..
– MahdiNajafi
Mar 22 at 20:05
It says right in the error:
need type assertion
. Also check the docs, because the package you're using probably has a convenience method to do this for you.– JimB
Mar 22 at 19:37
It says right in the error:
need type assertion
. Also check the docs, because the package you're using probably has a convenience method to do this for you.– JimB
Mar 22 at 19:37
godoc.org/github.com/spf13/viper#GetString
– Mad Wombat
Mar 22 at 19:53
godoc.org/github.com/spf13/viper#GetString
– Mad Wombat
Mar 22 at 19:53
Tnx "mad Wombat" ... My problem has been resolved ..
– MahdiNajafi
Mar 22 at 20:05
Tnx "mad Wombat" ... My problem has been resolved ..
– MahdiNajafi
Mar 22 at 20:05
add a comment |
1 Answer
1
active
oldest
votes
I believe the method viper.GetString
would work better than viper.Get
based on the documentation:
fyi, you can take a look at these things here: https://godoc.org/github.com/spf13/viper
mainServer := viper.GetString("mainServer.port")
gpServer := viper.GetString("gpServer.port")
However, you could assert the type directly...
Bear in mind this is ill-advised, you shouldn't do this as it will result in a panic if the type is not a string AND viper has the convenience method used above.
ln, _ := net.Listen("tcp", mainServer.(string))
gp_conn, _ := net.Listen("tcp", gpServer.(string))
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55306395%2fcant-convert-string-to-net-tcplistener-type%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
I believe the method viper.GetString
would work better than viper.Get
based on the documentation:
fyi, you can take a look at these things here: https://godoc.org/github.com/spf13/viper
mainServer := viper.GetString("mainServer.port")
gpServer := viper.GetString("gpServer.port")
However, you could assert the type directly...
Bear in mind this is ill-advised, you shouldn't do this as it will result in a panic if the type is not a string AND viper has the convenience method used above.
ln, _ := net.Listen("tcp", mainServer.(string))
gp_conn, _ := net.Listen("tcp", gpServer.(string))
add a comment |
I believe the method viper.GetString
would work better than viper.Get
based on the documentation:
fyi, you can take a look at these things here: https://godoc.org/github.com/spf13/viper
mainServer := viper.GetString("mainServer.port")
gpServer := viper.GetString("gpServer.port")
However, you could assert the type directly...
Bear in mind this is ill-advised, you shouldn't do this as it will result in a panic if the type is not a string AND viper has the convenience method used above.
ln, _ := net.Listen("tcp", mainServer.(string))
gp_conn, _ := net.Listen("tcp", gpServer.(string))
add a comment |
I believe the method viper.GetString
would work better than viper.Get
based on the documentation:
fyi, you can take a look at these things here: https://godoc.org/github.com/spf13/viper
mainServer := viper.GetString("mainServer.port")
gpServer := viper.GetString("gpServer.port")
However, you could assert the type directly...
Bear in mind this is ill-advised, you shouldn't do this as it will result in a panic if the type is not a string AND viper has the convenience method used above.
ln, _ := net.Listen("tcp", mainServer.(string))
gp_conn, _ := net.Listen("tcp", gpServer.(string))
I believe the method viper.GetString
would work better than viper.Get
based on the documentation:
fyi, you can take a look at these things here: https://godoc.org/github.com/spf13/viper
mainServer := viper.GetString("mainServer.port")
gpServer := viper.GetString("gpServer.port")
However, you could assert the type directly...
Bear in mind this is ill-advised, you shouldn't do this as it will result in a panic if the type is not a string AND viper has the convenience method used above.
ln, _ := net.Listen("tcp", mainServer.(string))
gp_conn, _ := net.Listen("tcp", gpServer.(string))
answered Mar 22 at 19:59
snassrsnassr
44058
44058
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55306395%2fcant-convert-string-to-net-tcplistener-type%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
It says right in the error:
need type assertion
. Also check the docs, because the package you're using probably has a convenience method to do this for you.– JimB
Mar 22 at 19:37
godoc.org/github.com/spf13/viper#GetString
– Mad Wombat
Mar 22 at 19:53
Tnx "mad Wombat" ... My problem has been resolved ..
– MahdiNajafi
Mar 22 at 20:05