- Setup
- Creating Channels
- Subscribing and Unsubscribing
- Uploading Video
- Liking and Disliking
- Commenting and Replying
- Liking, Disliking Comments and Replies
package main
import (
"fmt"
"example.com/pkgs/models"
)
func main() {
fmt.Println("Welcome!");
models.TestModel();
}
package main
import (
"fmt"
"example.com/pkgs/models"
)
func main() {
viewerChannel := &models.ChannelViewer{
LikesGiven: 0,
DislikesGiven: 0,
Comments: 0,
ChannelName: "Channel Name",
}
// But for simplicity, we'll do a one-liner. Learn more about the models from the documentation.
viewerChannel := &models.ChannelViewer{0,0,0,"Channel Name Here"};
fmt.Println(*viewerChannel);
}
We used &models.ChannelViewer
to set viewerChannel
as a pointer.
You can learn more about ChannelViewer
in the documentation
package main
import (
"fmt"
"example.com/pkgs/models"
)
func main() {
viewerChannel := &models.ChannelViewer{0,0,0,"Channel Name"};
creatorChannel := &models.ChannelCreator{[]models.Video{}, 0, "Channel Name"}
fmt.Println(*viewerChannel);
fmt.Println(*creatorChannel);
}
You can learn more about ChannelCreator
in the documentation
To do this, you must use a viewer channel to subscribe to a creator channel.
package main
import (
"fmt"
"example.com/pkgs/models"
)
func main() {
viewerChannel := &models.ChannelViewer{0,0,0,"Channel Name Here"};
creatorChannel := &models.ChannelCreator([]models.Video{}, 0, "Channel Name Here")
fmt.Println(*viewerChannel);
fmt.Println(*creatorChannel);
notification := viewerChannel.Subscribe(creatorChannel);
}
The Subscribe
method will return a string channel that can later be used as a notification whenever the subscribed creator uploads a new video.
You can learn more about channels here.
package main
import (
"fmt"
"example.com/pkgs/models"
)
func main() {
viewerChannel := &models.ChannelViewer{0,0,0,"Channel Name Here"};
creatorChannel := &models.ChannelCreator([]models.Video{}, 0, "Channel Name Here")
fmt.Println(*viewerChannel);
fmt.Println(*creatorChannel);
notification := viewerChannel.Subscribe(creatorChannel);
fmt.Println("Subscribed to " + creatorChannel.channelName);
viewerChannel.Unsubscribe(creatorChannel, notification);
fmt.Println("Unsubscribed " + creatorChannel.channelName);
}
With the Unsubscribe
method, you have to pass in notification as an argument to viewerChannel.Unsubscribe
, this is to close the notification channel so no further notification will be received.
You can learn more about closing channels here.
package main
import (
"fmt"
"example.com/pkgs/models"
)
func main() {
viewerChannel := &models.ChannelViewer{0,0,0,"Channel Name Here"};
creatorChannel := &models.ChannelCreator([]models.Video{}, 0, "Channel Name Here")
notification := viewerChannel.Subscribe(creatorChannel);
fmt.Println("Subscribed to " + creatorChannel.channelName);
firstVideo := creatorChannel.UploadVideo("Title", "Description", notification);
}
creatorChannel.UploadVideo
accepts three arguments: title
, description
, and the notification channel so that it can send pings or notifications to the receiver.
The receiver will be handled internally (it will print the received value) so no additional code is required.
creatorChannel.UploadVideo
will return a Video type. Learn more about channels here.
This method can only be called within a Viewer Channel and can only like or dislike Videos.
package main
import (
"fmt"
"example.com/pkgs/models"
)
func main() {
viewerChannel := &models.ChannelViewer{0,0,0,"Channel Name Here"};
creatorChannel := &models.ChannelCreator([]models.Video{}, 0, "Channel Name Here")
notification := viewerChannel.Subscribe(creatorChannel);
fmt.Println("Subscribed to " + creatorChannel.channelName);
firstVideo := creatorChannel.UploadVideo("Title", "Description", notification);
viewerChannel.LikeVideo(firstVideo);
}
viewerChannel.LikeVideo
will return an integer, which is the video's amount of likes.
package main
import (
"fmt"
"example.com/pkgs/models"
)
func main() {
viewerChannel := &models.ChannelViewer{0,0,0,"Channel Name Here"};
creatorChannel := &models.ChannelCreator([]models.Video{}, 0, "Channel Name Here")
notification := viewerChannel.Subscribe(creatorChannel);
fmt.Println("Subscribed to " + creatorChannel.channelName);
firstVideo := creatorChannel.UploadVideo("Title", "Description", notification);
viewerChannel.DislikeVideo(firstVideo);
}
viewerChannel.DislikeVideo
will return an integer, which is the video's amount of dislikes.
This method can only be called within a Viewer Channel and can only comment on Videos and reply to a Comment.
package main
import (
"fmt"
"example.com/pkgs/models"
)
func main() {
viewerChannel := &models.ChannelViewer{0,0,0,"Channel Name Here"};
creatorChannel := &models.ChannelCreator([]models.Video{}, 0, "Channel Name Here")
notification := viewerChannel.Subscribe(creatorChannel);
fmt.Println("Subscribed to " + creatorChannel.channelName);
firstVideo := creatorChannel.UploadVideo("Title", "Description", notification);
viewerChannel.LikeVideo(firstVideo);
commentOne := viewerChannel.CommentVideo(firstVideo, "Comment Message")
}
viewerChannel.CommentVideo
will return a Comment Object.
package main
import (
"fmt"
"example.com/pkgs/models"
)
func main() {
viewerChannel := &models.ChannelViewer{0,0,0,"Channel Name Here"};
creatorChannel := &models.ChannelCreator([]models.Video{}, 0, "Channel Name Here")
notification := viewerChannel.Subscribe(creatorChannel);
fmt.Println("Subscribed to " + creatorChannel.channelName);
firstVideo := creatorChannel.UploadVideo("Title", "Description", notification);
viewerChannel.likeVideo(firstVideo);
commentOne := viewerChannel.CommentVideo(firstVideo, "Comment Message");
replyOne := viewerChannel.ReplyComment(commentOne, "Reply Message");
}
viewerChannel.ReplyComment
will return a Comment Object.
Note that reply type is Comment which means you can stack reply with more replies.
package main
import (
"fmt"
"example.com/pkgs/models"
)
func main() {
viewerChannel := &models.ChannelViewer{0,0,0,"Channel Name Here"};
creatorChannel := &models.ChannelCreator([]models.Video{}, 0, "Channel Name Here")
notification := viewerChannel.Subscribe(creatorChannel);
fmt.Println("Subscribed to " + creatorChannel.channelName);
firstVideo := creatorChannel.UploadVideo("Title", "Description", notification);
viewerChannel.likeVideo(firstVideo);
commentOne := viewerChannel.CommentVideo(firstVideo, "Comment Message");
replyOne := viewerChannel.ReplyComment(commentOne, "Reply Message");
viewerChannel.LikeCommentOrReply(commentOne);
viewerChannel.LikeCommentOrReply(replyOne);
fmt.Println(commentOne.Likes, replyOne.Likes);
}
viewerChannel.LikeCommentOrReply
will return the comment or reply passed in from the argument.
package main
import (
"fmt"
"example.com/pkgs/models"
)
func main() {
viewerChannel := &models.ChannelViewer{0,0,0,"Channel Name Here"};
creatorChannel := &models.ChannelCreator([]models.Video{}, 0, "Channel Name Here")
notification := viewerChannel.Subscribe(creatorChannel);
fmt.Println("Subscribed to " + creatorChannel.channelName);
firstVideo := creatorChannel.UploadVideo("Title", "Description", notification);
viewerChannel.likeVideo(firstVideo);
commentOne := viewerChannel.CommentVideo(firstVideo, "Comment Message");
replyOne := viewerChannel.ReplyComment(commentOne, "Reply Message");
viewerChannel.DislikeCommentOrReply(commentOne);
viewerChannel.DislikeCommentOrReply(replyOne);
fmt.Println(commentOne.Dislikes, replyOne.Dislikes);
}
viewerChannel.DislikeCommentOrReply
will return the comment or reply passed in from the argument.
Congratulations! You have read the documentation all the way through. Now explore the source code and please tell me what I could improve.