Skip to content
This repository has been archived by the owner on Jul 31, 2023. It is now read-only.

Restore session after application restart #32

Open
tarikhagustia opened this issue Oct 9, 2020 · 3 comments
Open

Restore session after application restart #32

tarikhagustia opened this issue Oct 9, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@tarikhagustia
Copy link

Hi, @dimaskiddo looks like you have updated this repository again, nice work !
anyway do you have an idea to restore all session when application restarted?

@dimaskiddo
Copy link
Owner

Thank's @tarikhagustia 😄

It's really possible @rosseti has a good pull request about it, but i'am pending it for a long-long time until it's conflicting with my own update 😢 . Because i need to think about the pros and cons also in the security concern

@dimaskiddo dimaskiddo added the enhancement New feature or request label Oct 9, 2020
@hrizal
Copy link

hrizal commented Feb 15, 2021

i change main.go with ...

package main

import (
"fmt"
"log"
"time"
"os"
"os/signal"
"path/filepath"
"syscall"

"github.com/dimaskiddo/go-whatsapp-rest/internal"
"github.com/dimaskiddo/go-whatsapp-rest/pkg/router"
"github.com/dimaskiddo/go-whatsapp-rest/pkg/server"
wa "github.com/dimaskiddo/go-whatsapp-rest/pkg/whatsapp" 

)

// Server Variable
var svr *server.Server

// Init Function
func init() {
// Set Go Log Flags
log.SetFlags(log.Flags() &^ (log.Ldate | log.Ltime))

// Load Routes
internal.LoadRoutes()

// Initialize Server
svr = server.NewServer(router.Router)

}

// Main Function
func main() {

var files []string
// Starting Server
svr.Start()

time.Sleep(5 * time.Second) 

// reload all gob
gobpath := server.Config.GetString("SERVER_STORE_PATH")
a := server.Config.GetInt("WHATSAPP_CLIENT_VERSION_MAJOR")
b := server.Config.GetInt("WHATSAPP_CLIENT_VERSION_MINOR")
c := server.Config.GetInt("WHATSAPP_CLIENT_VERSION_BUILD")

err := filepath.Walk(gobpath, func(path string, info os.FileInfo, err error) error {
	if filepath.Ext(path) == ".gob" {
       files = append(files, filepath.Base(path))
	}   
    return nil
})

if err!=nil {
	log.Println(err)
}

for _, file := range files {

	jid := file[0:len(file)-4]
	gobfile := server.Config.GetString("SERVER_STORE_PATH") + "/" + jid + ".gob"
	qrstr := make(chan string)
	errmsg := make(chan error)
	log.Println("Load "+jid)
	go wa.WASessionConnect(jid,a,b,c,30,gobfile,10,qrstr,errmsg)
	time.Sleep(1 * time.Second) 
}


	// Make Channel for OS Signal
sig := make(chan os.Signal, 1)

// Notify Any Signal to OS Signal Channel
signal.Notify(sig, os.Interrupt)
signal.Notify(sig, syscall.SIGTERM)

// Return OS Signal Channel
// As Exit Sign
<-sig

// Log Break Line
fmt.Println("")

// Stopping Server
defer svr.Stop()

}

@dimaskiddo
Copy link
Owner

dimaskiddo commented Feb 24, 2021

@hrizal it should not to use WASessionConnect function but WASessionRestore for more simple if you only need to restore session from gob file

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants