Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

migration to go mod, moving from standard library http handler to echo #17

Open
wants to merge 63 commits into
base: master
Choose a base branch
from

Conversation

joicemjoseph
Copy link

No description provided.

@joicemjoseph joicemjoseph marked this pull request as draft July 16, 2020 16:57
@joicemjoseph
Copy link
Author

@navaneeth please review

@joicemjoseph joicemjoseph marked this pull request as ready for review July 17, 2020 05:06
@joicemjoseph
Copy link
Author

Good to go
Screenshot 2020-08-09 at 8 56 02 AM

@subins2000
Copy link
Member

I don't know Go, is echo a HTTP library like express in nodejs ? Would it be possible to add an authentication to only allow some people to add words with /learn endpoint ?

@joicemjoseph
Copy link
Author

Yes, It is possible. We can do it without any extra libraries. They have a middleware. We can do the same without any third party library. On request, encode username and password in base64 format and send it on Authentication header, decode and string match credentials and can proceed.

@subins2000
Copy link
Member

I tried the branch, but getting this error on learn handler.

curl 'http://localhost:8080/learn' -H 'Origin: http://localhost:8080' -H 'DNT: 1' -H 'Connection: keep-alive' -H 'Referer: http://localhost:8080/' --data-raw $'{"text":"\u0d15\u0d4d","lang":"ml"}'

gives :

{"message":"unable to find language"}

image

main.go Outdated
varnamdConfig = initConfig()
startedAt = time.Now()

runtime.GOMAXPROCS(runtime.NumCPU())
flag.Parse()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be called before initConfig() is called, otherwise flag values won't be set

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will check this today.

@subins2000
Copy link
Member

subins2000 commented Sep 3, 2020

Running varnamd -enable-download ml,hi -sync-interval 1 doesn't seem to do anything too. Idk what's the expected working @navaneeth

@joicemjoseph
Copy link
Author

joicemjoseph commented Sep 3, 2020

I tried the branch, but getting this error on learn handler.

curl 'http://localhost:8080/learn' -H 'Origin: http://localhost:8080' -H 'DNT: 1' -H 'Connection: keep-alive' -H 'Referer: http://localhost:8080/' --data-raw $'{"text":"\u0d15\u0d4d","lang":"ml"}'

gives :

{"message":"unable to find language"}

image

try
curl -XPOST 'localhost:8080/learn' -d '{"word":"\u0d15\u0d4d","lang":"ml"}' -i -H 'Content-Type: application/json'

PS: Make sure you have mentioned content-type

@subins2000
Copy link
Member

Didn't work, same error happens. Can you try it out in varnamd's UI and see if it works on your side ?

image

@joicemjoseph
Copy link
Author

Didn't work, same error happens. Can you try it out in varnamd's UI and see if it works on your side ?

image

There was an issue, which I mistaken for a json element key. I resolved it. But I found out that request's content type is not 'application/json' but 'form-url-encoded'.

The request is made from https://github.com/varnamproject/varnamd/blob/master/ui/javascripts/varnam.js#L77 It is in the minified form. @subins2000 could you send me a patch by adding content type as 'application/json' ?

Screenshot 2020-09-03 at 5 12 41 PM

@joicemjoseph joicemjoseph marked this pull request as draft September 3, 2020 11:58
@joicemjoseph
Copy link
Author

moved to draft as I found a bug in download content encoding

@joicemjoseph joicemjoseph marked this pull request as ready for review September 3, 2020 17:26
@subins2000
Copy link
Member

Can confirm, learn endpoint now gives a "success" response. Thanks for the fix!

@joicemjoseph
Copy link
Author

joicemjoseph commented Sep 15, 2020

There is a default value in varnamd, without any config file, it will run on port 8080.

as a workaroud, we can add env variable as well as config flag.

(Thanks for pointing out ibus-varnam's varnamd dependency. I forgot that)

@subins2000
Copy link
Member

Perhaps allow usage of flags that'll override the config file ?

@joicemjoseph
Copy link
Author

joicemjoseph commented Sep 17, 2020

Perhaps allow usage of flags that'll override the config file ?

1f62ad1 resolved this

subins2000 and others added 9 commits September 28, 2020 00:23
Add endpoint for downloading Varnam Symbol Table, Removing Word, Cache Improvements
* Add endpoint for uploading a file and learning from it

* Add /learn/upload enpoint for files to be uploaded and learnt

* Make /learn endpoints under auth

* refactored code

* Refactor, move functions to better suited files, use temp dir for upload

* Disable auth by default

* Change tmpdir

Co-authored-by: Joice <[email protected]>
* Add /packs, /packs/:langCode endpoint, basic packs structure

* Funcs should return errors too

* Add /packs/:langCode/:packIdentifier endpoint for downloading a pack

* Add endpoint to download pack from upstream

* Enable internal API by default

* Add learning from pack file

* Add endpoint to get a pack version info & a /download to download that pack
@navaneeth
Copy link
Member

There are so many changes. Not sure I have gone through and tested fully. @joicemjoseph , @subins2000 tested this?

@joicemjoseph
Copy link
Author

Yep. There are a lot of changes. Yet more changes are on pipeline. We have tested. But, Subin have made some PR to my fork. I will merge them. Then we can merge this PR. How that would be.
??

@navaneeth
Copy link
Member

@joicemjoseph Sure. That makes sense

* Add different endpoints for pack & diff pack versions

* Show 404 if no pack found

* packs.json should be updated when a new pack is downloaded from upstream

* Disallow pack download if already installed

* Test upstream URL

* Refactor better

* Assign small-caps JSON property names
@subins2000
Copy link
Member

@navaneeth This PR is now complete. It'd be great if you can give org access to both of us so that we can work straight on varnamd (with PRs of course) skipping the fork of a fork changes.

subins2000 and others added 4 commits October 8, 2020 15:55
* Remove usage of packs.json and use pack.json inside different packs

* Update pack.json when packs are downloaded

* Packs are now trained files to import from and not files to learn from

* Show error if pack import failed, don't update pack.json then

* Cache packs info for faster requests and avoid recurrent disk reads

* Compress pack downloads into gzip, considerable filesize decrease

* Use new vpf extension for pack file

* division is the correct way to convert to int
.vlf - Varnam Learnings File
@subins2000
Copy link
Member

We've been running this changed varnamd here and on the desktop app. 90% of these changes have been tested and works well.

Recommending this to be merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants