Skip to content

I'm learning GoLang and they say experience is the best teacher so I decided to make a small useless project implementing what I've learned so far. This repository is about Youtube's features but modified a little bit.

Notifications You must be signed in to change notification settings

CantCode023/YoutubeFeatures

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 

Repository files navigation

! IMPORTANT !

This is a beginner mini project I made to understand channels, functions, pointers, etc. in depth. If you see any stuffs that could be improved, feel free to let me know on my Discord Blue Duck#8344 as I'm still learning GoLang and I'm looking forward to improve my skills. Thanks!

Table Of Contents


Setup

package main

import (
    "fmt"
    "example.com/pkgs/models"
)

func main() {
    fmt.Println("Welcome!");
    models.TestModel();
}

Creating Channels

Create a Viewer Account

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


Create a Creator Account

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


Subscribing and Unsubscribing

To do this, you must use a viewer channel to subscribe to a creator channel.

Subscribe

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.


Unsubscribe

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.


Uploading Video

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.


Liking and Disliking

This method can only be called within a Viewer Channel and can only like or dislike Videos.

Like

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.


Dislike

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.


Commenting and Replying

This method can only be called within a Viewer Channel and can only comment on Videos and reply to a Comment.

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.


Reply

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.


Liking and Disliking Comments or Replies

Liking Comments or 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.

Disliking Comments or 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.DislikeCommentOrReply(commentOne);
    viewerChannel.DislikeCommentOrReply(replyOne);
    fmt.Println(commentOne.Dislikes, replyOne.Dislikes);
}

viewerChannel.DislikeCommentOrReply will return the comment or reply passed in from the argument.

Conclusion

Congratulations! You have read the documentation all the way through. Now explore the source code and please tell me what I could improve.

About

I'm learning GoLang and they say experience is the best teacher so I decided to make a small useless project implementing what I've learned so far. This repository is about Youtube's features but modified a little bit.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages