课程: Practice It: Go REST API Server

今天就学习课程吧!

今天就开通帐号,24,700 门业界名师课程任您挑!

Check it: Create a struct and receiver methods

Check it: Create a struct and receiver methods - Go教程

课程: Practice It: Go REST API Server

Check it: Create a struct and receiver methods

(title pulses) - [Instructor] Now that you've tried it, let's check it against my solution. So I'll walk you through how I solve the challenge. So first we'll add the sql lite 3 library. And we'll add the internal go library. And then we will create our struct. So we'll have the type App, which will be a struct. And we'll add the field DB, which will be. And then we'll add Port here too. Which will be a string. And then, next, what we'll do is we'll add another function called Initialize. And in this case, we'll add it as receiver method. I'll have Initialize. And in Initialize, we will create the DB connection. Sqlite3. And we will add the DB. We will check for an error. And we will log a fatal error. And we still have our Run function. Which we will also add receiver. In this case, I'll be on the Port. And we won't need this. I'll add it here. And now we'll run go mod tidy to update…

内容