This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
version: "2" | |
networks: | |
gitea: | |
external: false | |
volumes: | |
gitea: | |
driver: local |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func (u *User) Follow(db *gorm.DB, user User) { | |
if !u.IsFollowing(db, user) { | |
db.Model(&u).Association("Followers").Append(&user) | |
} | |
} | |
func (u *User) Unfollow(db *gorm.DB, user User) { | |
if u.IsFollowing(db, user) { | |
db.Model(&u).Association("Followers").Delete(&user) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DB.Model(&user).Association("Followers").Delete(&User{Name: "usuario2"}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DB.Model(&user).Association("Followers").Append(&User{Name: "usuario2"}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type User struct { | |
gorm.Model | |
UserSession | |
Username string `gorm:"type:varchar(32);UNIQUE"` | |
Email string `gorm:"type:varchar(256);UNIQUE"` | |
Password string `gorm:"type:varchar(128)"` | |
AboutMe string `gorm:"type:varchar(512)"` | |
LastSeen string `gorm:"type:varchar(20)"` | |
Followers []*User `gorm:"many2many:followship;association_jointable_foreignkey:follower_id;jointable_foreignkey:followed_id"` | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cat >> /etc/cron.hourly/certbot << EOF | |
/usr/bin/certbot renew | |
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
cat >> /etc/apt/sources.list << EOF | |
deb http://ftp.debian.org/debian jessie-backports main | |
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func EditProfileFn(c *gin.Context) { | |
currentUser := models.User{} | |
session := sessions.Default(c) | |
u := session.Get("user") | |
if u != nil { | |
currentUser = u.(models.User) | |
} | |
dbc, exist := c.Get("db") | |
if !exist { | |
c.HTML(http.StatusOK, "index", gin.H{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func NewServer() *gin.Engine { | |
RegisterSerializers() | |
// gin.SetMode(gin.ReleaseMode) // Production mode | |
srv := gin.New() | |
srv.Use(RegisterLogger(Logger)) | |
srv.Use(gin.Logger()) | |
srv.Use(RegisterRecovery()) | |
srv.Use(ResisterDatabase()) | |
srv.Use(RegisterSession()) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
func main() { | |
database.DB = database.Init() | |
defer database.DB.Close() | |
out, err := os.OpenFile("./goblog.log", os.O_CREATE|os.O_WRONLY|os.O_APPEND, 0666) | |
if err != nil { | |
panic(err) | |
} | |
defer out.Close() | |
router.Logger = out |